Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

How to modify your apk using apktool, jarsigner, and zipaligner
Started by mutatron Dec 14 2013 05:03 PM

3 replies to this topic
apktool jarsigner zipaligner
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 32 posts
  • Enterprise

Because of its numerous UI features, I needed to limit my OrbitLab app to tablet-sized devices, which is easy to do in iOS since there's only the iPhone and iPad, but for Android it's a bit more difficult. When you upload your beta apk, there are nearly 4,000 devices available, and more to be available in the future, so it would be a pretty big job to try to go through and check off all the excluded devices.


After uploading to Google Play, I also noticed that my apk listed three supported languages: es, he, and iw. In fact I had taken the trouble of localizing my app in 29 extra languages using Smooth Localize, so I wanted this to be reflected in my apk, in case any Android stores were looking at that to decide on how to display it in other locales.




You can decompile your apk with apktool. The apktool installer for Windows needs to have something like 7-zip to unpack it. Here's a tutorial about how to install it.


Once you have that up and running, you only need to do something like the following:

apktool d -f OrbitLab.apk Orbitlab1.0b10

Where "d" means decompile and "-f" means overwrite an existing decompiled folder.


Restricting to tablets


Inside your folder you can now see a file called AndroidManifest.xml. To restrict to tablets, open that with a text editor and add the lines:

<supports-screens android:smallScreens="false"
    android:xlargeScreens="true" />

Add these prior to the line:

<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="OrbitLab">

While you're in there, you need to change the package in the first line from:


to something like:


Otherwise Google Play will give you an error after uploading your apk.


Making languages known


If you go into your decompiled apk folder, you'll find a res folder. Inside of that there will be a values folder with some default strings in a strings.xml file. You'll also see values-esvalues-he, and values-iw, which contain their own strings.xml with their own translations. It's these folders and files Google Play looks at to determine how many languages your app is translated into.


Bear in mind, I don't even know if this matters, so I might be doing unnecessary effort. But I also found that including the folder alone did nothing, because the compiler removes it if it's empty. So you have to have that strings.xml file in there. I edited it down to one line, since they're all just Facebook strings of no importance to my app.


Then I copied the folders and renamed like so:




Now recompile using apktool like this:

apktool b OrbitLab1.0b10 OrbitLab_temp.apk



Next you have to sign the apk using jarsigner. If you upload without signing, Google Play will give you an error. I'll assume you've already set up all the keystore and stuff like that. Assuming you have, then all you have to do is this, where <keystore path> of course is your own path to your keystore:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore C:\<keystore path>\orbitlab.keystore Orbitlab_temp.apk aliasname



Finally you have to zipalign the signed apk. If you upload without zipaligning, Google Play will give you an error. This is pretty easy, just:

zipalign -fv 4 OrbitLab_temp.apk OrbitLab.apk 

An added benefit of all this is that my apk went from 22 megs to 14.


Now my apk shows that it's been localized in default + 29 languages, and the number of supported devices is reduced to under 1000.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 60 posts
  • Corona SDK

This is pretty awesome and quite usefull -I was strugling with the random languages google would pick up from my apk!

Tks for sharing!!

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 124 posts
  • Corona SDK

I need to add: android:largeScreens="true" but apktool won't install properly on my macbook pro running Maverick. any suggestions on other ways to change the manifest?? 



[TOPIC: post.html]

Dave Haynes

[GLOBAL: userInfoPane.html]
Dave Haynes
  • Contributor

  • 233 posts
  • Corona SDK

Can't you just do this in the build.settings?

supportsScreens =
               resizeable = false,
               smallScreens = true,
               normalScreens = true,
               largeScreens = true,
               xlargeScreens = true