I need to modify an existing APK, modify the sources and then recompile it.
But now I would like to know how to recompile the java files and put them back into a jar file! (the jar part should be easy, the main problem seems to be how to recompile the java files for android)
I know that an other solution is to use apktool and then modify the smali files, but it seems to be really complicated when we want to add a lot of code!
My application is a basic a HelloWorld whitout obfuscation.
This question is related to
java
android
decompiling
recompile
The answers are already kind of outdated or not complete. This maybe works for non-protected apks (no Proguard), but nowadays nobody deploys an unprotected apk. The way I was able to modify a (my) well-protected apk (Proguard, security check which checks for "hacking tools", security check, which checks if the app is repackaged with debug mode,...) is via apktool as already mentioned by other ones here. But nobody explained, that you have to sign the app again.
apktool d app.apk
//generates a folder with smali bytecode files.
//Do something with it.
apktool b [folder name] -o modified.apk
//generates the modified apk.
//and then
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore modified.apk androiddebugkey
//signs the app the the debug key (the password is android)
//this apk can be installed on a device.
In my test, the original release apk had no logging. After I decompiled with apktool I exchanged a full byte code file without logging by a full byte code file with logging, re-compiled and signed it and I was able to install it on my device. Afterwards I was able to see the logs in Android Studio as I connected the app to it.
In my opinion, decompiling with dex2jar
and JD-GUI
is only helpful to get a better understanding what the classes are doing, just for reading purposes. But since everything is proguarded, I'm not sure that you can ever re-compile this half-baked Java code to a working apk. If so, please let me know. I think, the only way is to manipulate the byte code itself as mentioned in this example.
I know this question is answered still, I would like to pass an information how to get source code from apk with out dexjar.
There is an online decompiler for android apks
I don't know how reliable is this.
@darkheir Answer is the manual way to do decompile apk. It helps us to understand different phases in Apk creation.
Once you have source code , follow the step mentioned in the accepted answer
Report so many ads on this links
Another online Apk De-compiler @Andrew Rukin : http://www.javadecompilers.com/apk
Still worth. Hats Off to creators.
I know this question has been answered and I am not trying to give better answer here. I'll just share my experience in this topic.
Once I lost my code and I had the apk
file only. I decompiled it using the tool below and it made my day.
These tools MUST be used in such situation, otherwise, it is unethical and even sometimes it is illegal, (stealing somebody else's effort). So please use it wisely.
Those are my favorite tools for doing that:
and to get the apk from google play you can google it or check out those sites:
On the date of posting this answer I tested all the links and it worked perfect for me.
NOTE: Apk Decompiling is not effective in case of proguarded code. Because Proguard shrink and obfuscates the code and rename classes to nonsense names which make it fairly hard to understand the code.
Bonus:
First download the dex2jar tool from Following link http://code.google.com/p/dex2jar/downloads/list
Extract the file it create dex2jar
folder
Now you pick your apk file and change its extension .apk to .zip after changing extension it seems to be zip file then extract this zip file you found classes.dex
file
Now pick classes.dex file and put it into dex2jar
folder
Now open cmd window and type the path of dex2jar
folder
Now type the command dex2jar.bat classes.dex
and press Enter
Now Open the dex2jar
folder you found classes_dex2jar.jar
file
Next you download the java decompiler tool from the following link http://java.decompiler.free.fr/?q=jdgui
Last Step Open the file classes_dex2jar.jar
in java decompiler tool now you can see apk code
dex2jar with jd-gui will give all the java source files but they are not exactly the same. They are almost equivalent .class files (not 100%). So if you want to change the code for an apk file:
decompile using apktool
apktool will generate smali(Assembly version of dex) file for every java file with same name.
smali is human understandable, make changes in the relevant file,
recompile using same apktool(apktool b Nw.apk <Folder Containing Modified Files>
)
I know this question is answered still and I am not trying to be smart here. I'll just want to share another method on this topic.
Download applications with apk grail
APK Grail providing the free zip file of the application.
This is a way:
Using apktool
to decode:
$ apktool d -f {apkfile} -o {output folder}
Next, using JADX (at github.com/skylot/jadx)
$ jadx -d {output folder} {apkfile}
2 tools extract and decompiler to same output folder.
Source: Stackoverflow.com