Decompile an APK, modify it and then recompile it

darkheir picture darkheir · Sep 11, 2012 · Viewed 166.6k times · Source

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.

Answer

darkheir picture darkheir · Sep 11, 2012

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 resources 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 resources and the manifest with the ones I obtained with apktool
  • I paste the java files I extracted from the Jar in the src folder (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!