Wednesday, August 28, 2013

How to master apktool compile/decompile [Easy guide]

Some people are unfamiliar with apktool, also someone asked me how to use it and how to sign system apps
So first required downloads:
1- Java Runtime Environment: from HERE Or from Apktool's website HERE
2- Apktool: from HERE
  - After installing java runtime, extract Apktool.zip so aapt.exe and apktool.jar in "C:\"

You should know that apktool can't decompile/compile 3rd party applications.
It can work on system files only.
You can't decompile 3rd party apps unless you have the source code.

First to decompile any sys app, install your framework::
apktool if framework-res.apk

Let's say we will work on Settings application.
Make 2 copies of Settings.apk - put a copy in "C:\" and the original in anywhere you know.

- Shift + Right click in an empty place in folder "C:\" and select "open command windows here"
- To decopmile type the following without quotes
   " apktool d Settings.apk "
- A folder will be created inside "C:\" named "settings" inside it you will find other folders.
- The codes of the application are inside the folder "smali".
- The images are inside "res/drawables".
- Text are found inside "res/strings".
- Assets folder contains other files needed by an application to run (not necessarily exist).
- Androidmanifest.xml contains application information and permissions and such.

After modifying the application till your needs you will compile just by typing the following
" apktool b settings "
You will find the new apk in "dist" folder inside "settings" folder

DON'T SIGN THE APK AND PUSH IT..
- Open the apk as a zip with winrar
- Let's say you modified strings.xml
- Copy resources.arsc from the new apk to the original apk

- Or you modified smali's
- Copy classes.dex from the new apk to the original apk

Then push the apk using adb or root explorer or anything you want and change permissions to at least rw-r-r