Search code examples
javaandroidandroid-studiodex

How to convert .dex files to android studio project


I have an apk debug file and a zip file with same contents. There are some .dex files META-INF, AndroidManifest.xml and so on. Is there any way to import it to an android studio project to edit app classes?


Solution

  • Yes, but it's going to be a hassle to do.

    The JADx GUI can open an APK and will decompile all classes and resources in a read-only mode. You can then use the "Export to Gradle Project" function to do exactly what it says.

    However, it's not exactly reliable. Sometimes it doesn't extract so you need to do it again. When it does finally create a project, you'll notice that the Gradle version is sorely outdated, so you'll need to update it.

    Other things to note:

    • If the project uses libraries, they will be integrated into the project tree in Android Studio. This is because libraries are built into the APK during compilation.
    • There will be potentially thousands of duplicated resources that you'll have to manually delete.
    • There will be invalid resource folders
    • There will be invalid Java code:
      • JADx can't decompile everything, and will leave empty methods
      • If there are multiple anonymous classes of the same type used in a class, JADx usually only decompiles one.

    As someone who's done this, it's honestly easier to just learn Smali and use APKTool.