How to modify your apk using apktool, jarsigner, and zipaligner

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.

 

Decompiling

 

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:normalScreens="false"
    android:largeScreens="true"
    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:

package="com.ansca.corona"

to something like:

package="com.orbitlabapp.com.OrbitLab"

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-es, values-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:

values-ar
values-cs
values-da
values-de
etc.

Recompiling

 

Now recompile using apktool like this:

apktool b OrbitLab1.0b10 OrbitLab_temp.apk

Signing

 

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

Zipaligning

 

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值