I need to modify an existing APK, modify the sources and then recompile it.
- I can decompile it using dex2jar or apktool, it's working great
- From the jar file I can obtain the java sources (using jd-gui)
- Then I can modify the java files
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.
Thanks to Chris Jester-Young I managed to make it work!
I think the way I managed to do it will work only on really simple projects:
- With Dex2jar I obtained the Jar.
- With jd-gui I convert my Jar back to Java files.
With apktool i got the android manifest and the ressources files
In Eclipse I create a new project with the same settings as the old one (checking all the information in the manifest file)
- When the project is created I'm replacing all the ressources and the manifest with the ones I obtained with apktool
- I paste the java files I extracted from the Jar in the src foled (respecting the packages)
- I modify those files with what I need
- Everything is compiling!
/!\ be sure you removed the old apk from the device an error will be thrown stating that the apk signature is not the same as the old one!
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
- Upload apk from local machine
- Wait some moments
- Download source code in zip format
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
Another online Apk De-compiler @Andrew Rukin : http://www.javadecompilers.com/apk
Still worth. Hats Off to creators.
First download the dex2jar tool from Following link http://code.google.com/p/dex2jar/downloads/list
Extract the file it create
dex2jar
folderNow 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
fileNow pick classes.dex file and put it into
dex2jar
folderNow open cmd window and type the path of
dex2jar
folderNow type the command
dex2jar.bat classes.dex
and press EnterNow Open the
dex2jar
folder you foundclasses_dex2jar.jar
fileNext 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
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:
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>
)
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.
Easy way: Using Online APK Decompiler
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.
Use luckypatcher and remove your license verification than you do not have to sign apk. Use WINRAR to replace your modified source code without decompile apk.
One should change the file extension from .apk
to .zip
. Then extract the files, modify them and then compress them to .zip
and remember to rename the extension back to .apk
.
For doing this we don't even have to use any computer. I prefer ES file explorer, which can also help to view and edit the source code.
来源:https://stackoverflow.com/questions/12370326/decompile-an-apk-modify-it-and-then-recompile-it