APKtool - Modify your own APKs

APKtool - Modify your own APKs
APKtool USAGE IN WINDOWS
by Robbie Hood

Before you start this you should check out my guide on Android Debug Bridge
apktool.png


APKTool is a tool (made by Brut.all) which decompiles and recompiles android APKs. If you know what you are doing, it also allows you to debug the smali code step by step. In our case it will enable us to modify APK files.

The Google.Code page for APKTool is here

We are a bit in front of Google pages at the moment thanks to Ficeto.
He compiled our own APKtool from the new baksmali/smali sources, so for modding ICS files take this one:


You need to do the following preparations:

1. Download Java JRE
2. Download the prepackaged APKTool zip
3. Extract them to a directory you will remember
4. Extract framework-res.apk AND apk files you want to decompile from the ROM and copy them to the root directory of APKTool. (for Samsung ROMs take twframework-res.apk also)

This step must be completed every time you are dealing with APKTool:

1. Open a command window
2. Navigate to the root directory of APKtool and type the following command:

apktool if framework-res.apk

The output should be:

I: Framework installed to: C:\Users\robbie\apktool\framework\1.apk

This step does the actual decompiling of the APK (I will assume that the chosen APK is Settings.apk):

apktool d Settings.apk

The output should be:

I: Loading resource table…
I: Decoding resources…
I: Copying assets and libs…

After doing that, a new directory with the name of the APK you decompiled should have been created. You need to:

1. Change into the newly created directory.
2. Now you can modify the apk if you know where to look.

Enter the following command to recompile your edited and translated APK (assuming that Settings.apk is the chosen APK):

apktool b Settings

The output should be:

I: Checking whether sources has changed…
I: Smaling…
I: Checking whether resources has changed…
I: Building resources…
I: Building apk file…

You may get a couple of these messages:

aapt: warning: string ‘app_killed_message’ has no default translation in C:\Users\robbie\Desktop\NF\framework-res\res; found: fr it ja

aapt: warning: string ‘global_action_reboot’ has no default translation in C:\Users\robbie\Desktop\NF\framework-res\res; found: fr it ja

aapt: warning: string ‘reboot_system’ has no default translation in C:\Users\robbie\Desktop\NF\framework-res\res; found: fr it ja

aapt: warning: string ‘toast_reboot_recommend’ has no default translation in C:\Users\robbie\Desktop\NF\framework-res

However, it will build the apk anyway.
These messages mean that some strings don’t have values. It is only an issues if the text im blue includes your translation language.

Once that is done, two directories will have been created within the decompilation directory. One will be called “dist”, and this is where it will place a built, but not signed, apk file. The other one is called “build”, and here it will place everything “loose” (the contents of the APK).

I have trouble using the APK files. It spits out in the /dist folder (they force close if they are an application, or bootloop it a framework-res.apk; the reason is because Android will not accept APK files that are not signed)
Instead, copy the resources.arsc from the /build directory into the original framework-res from the rom (just overwrite the old resources.arsc one with the new one)

NOTE FROM ficeto: the files that need to stay original are AndroidManifest.xml and the META-INF folder in the root of the apk. On windows, the best practice for me is to use winrar to open the original apk (make a backup before that), delete everything except the things I mentioned, then in drop everything from the new compiled apk (except AndroidManifest.xml). That will keep the signatures of the needed files and the apk will install and work fine.



edited by arawn
Aug 5, 2012
comnam90 likes this.