Thursday, December 8, 2011

Apktool - What it is and how to use it (Windows)

Windows APKTool
The Apktool is probably my best friend in the Android development world. Its purpose is very simple, it decodes an APK file back to its original form, then rebuilds it after modifcations have been made to smali code or XMLs. 
As taken from the google source code web site (brut.alll): "It is NOT intended for piracy and other non-legal uses. It could be used for localizing, adding some features or support for custom platforms and other GOOD purposes. Just try to be fair with authors of an app, that you use and probably like."
Some good uses of apktool are things like changing or removing options from the settings menu, etc, but it really can enable you to do almost anything to the OS, with the creativity and knowledge.

How to use it!
Before you begin, it's a good idea to have the following installed and set up:  JDK & JRE from HERE


Decompiling with APKTOOL - step by step:

1. You can either visit the google code site for apktool and read through their instructions, or use our pre-packaged APKTOOL.rar available here.
2. Extract the contents to a file you will remember, as you will be working from there in command prompt! I'd recommend putting it with your platform-tools if you haven't added them to your path, as this will make editing recently pulled applications easier.
3. Now, if the apk you want to edit is on your phone, use adb to pull it. If you're unsure of how to do this, go back to our beginner guides and read up on adb and the SDK.
4. Pull framework-res.apk from the phone, as some applications will require this to be decoded.
5. Once framework-res.apk has been pulled, type the following command:
apktool if framework-res.apk
To break that down, you're telling apktool to if (install framework) and then specifying the apk. You should see the following output:
I: Framework installed to C:\whatever\your\path\is\framework\1.apk
Now it's time to decompile the APK. 
6. Type the following:
apktool d Settings.apk Settings
Of course, replace Settings.apk with the name of the application you want to decompile. To give you more of an explanation, you're telling apktool to d(decompile/decode) Settings.apk, and put the output in a folder called Settings. The folder part, Settings isn't necessary, I just included it so you could see that it was an option. 
You should then see the following outputs if its working:
I: Loading resource table...
I: Decoding resources...
I: Copying assets and libs...
Voila... your decompiled application will now be sat in the folder you specified above (we specified Settings). 

Rebuilding the APK after making modifications - step by step

1. Simply type the following command:
apktool b Settings Settings-new.apk
To break that down, you're telling apktool to b (build) the contents of the Settings folder into an apk called Settings-new.apk
You should see output similar to this:
I: Checking whether sources has changed…
I: Smaling…
I: Checking whether resources has changed…
I: Building resources…
I: Building apk file…
2. Once done, you will NOT be using the apk file you have just created. The reason being, for one it's not signed. Two... it often causes me problems. Instead, you need to open both the original Settings.apk and Settings-new.apk in 7-zip, and copy over the files you have changed from the NEW one to the ORIGINAL. If you have modified /res/values/*.xml, it's likely that these have been compiled into a file called resources.arsc. If that is the case, copy resources.arsc only. 
3. That's it! Add the new file to your ROM or push it back to the phone!

No comments:

Post a Comment

thank you