[Android Themes] Raiz:
III-Decompile

​

This is getting serious now.

If you want to modify the apk, you need to have what’s inside: the code.

A)Resources: Decompile Binary XMLs to Human-Readable XMLs:

​

We use APKtool for that, it decompiles the resources.arsc file to the res folder, and decodes binary XMLs to human-readable XMLs.

1-How to install APKtool:

​

How to install APKtool​

2-How to use APKtool:

​

There are 3 main commands you need to know about:

apktool d [nameoftheapk].apk​

Used to decompile the apk. There are several options you can use with that command, they're specified in APKtool's documentation (in the credits).

apktool if [nameoftheframework].apk​

Used to set the framework files to decompile properly APKs. Usually some OEMs add framework APKs into Android for their apps to work, so we need to find and copy them, then “install” them with the apktool if command to APKtool. You can learn more about that on APKtool's website (in the credits).

apktoool b [nameoftheapk].apk​

Used to recompile the apk. The final apk can be found inside the decompiled apk’s folder, in a subfolder named dist. You can also use various options with that command (listed in the documentation, link in the credits).

B) Decompile Classes.dex to smali:

​

APKtool also convert classes.dex files to .smali files, but keep at mind that you won’t be able to see the java source code in those files.

The .dex extention is for Dalvik Executable, which is very self-explanatory, and is also a binary format. APKtool turn them into .smali files, which are Human-readable files, not in java, but still! And if you want to modify the code, you’ll have to learn smali. (covered in the next part, good luck with that lol)

C)Read java source code :

​

There’s actually a way to see the java source code of an Android app, using some tools:

JD-GUI (or any other java decompiler)

Dex2jar

First turn the classes.dex files into .jar files with this command using Dex2jar:

./d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk​

(Execute the .bat if you’re on windows)

Quick explanation:

./d2j-dex2jar.sh: execute the dex2jar script

-f: replace the previous jar file named the same as output_jar.jar

-o output_jar.jar : set a name to the output jar file

apk_to_decompile.apk: name of the apk file you’re taking care of

Then read the jar file using JD-GUI (or any other java decompiler). It’s a quite simple software, lite weight, and you can download and run the java version without installing anything else.

Dex2jar isn’t updated anymore (since 2015), so there are errors when decompiling. You’ll be able to get a .jar file but it’ll be incomplete or not identical to the original one, that’s why this tool doesn’t allow one to modify java source directly. But you can get a great understanding of how this app works.

C) Nice tools from the XDA community:

​

• Tickle My Android (TMA) by @Ticklefish

A tool that ease the work with APKtool, amazing one!

• APK Easy Tool by @evildog1

Also works with APKtool, I don’t use it often, but it is great!

• Other tools:

Let me know :)

Credits, links for this part:

Stack Overflow Post

Documentation for APKtool

Another SO Post

@Rizal Lovins ’

" [Share Latest Apktool 4.2.2/Guide/Tutorial/] How to Decompile/Compile/Sign Apk/Jar "

@A_U ’s

" [GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps "