Is there a way to get the source code from an APK file?

前端 未结 27 1843
难免孤独
难免孤独 2020-11-21 06:56

The hard drive on my laptop just crashed and I lost all the source code for an app that I have been working on for the past two months. All I have is the APK file that is st

相关标签:
27条回答
  • 2020-11-21 07:48

    I'll show you other way to decompile the .apk files.

    You can follow the first 2 steps from "prankul garg". So you have another opportunities:

    Step 3':

    Download the "JD-GUI", thats easy to found this one. Open your .jar file in "jd-gui.exe". (File > Open file > 'found your .jar file'). After this procedure, you can save all resources in a .zip file.

    So,

    1st - You have to rename the .apk file to .zip

    2nd - You have to decode .dex file (if you want, decode the .apk file to dex2jar, that's possible)

    3rd - You have to decode .jar file with JD-GUI

    0 讨论(0)
  • 2020-11-21 07:48

    You can try DexPatcher. It even integrates with Android Studio. It uses Apktool and Dex2Jar internally.
    You can use those tools independently as well. Apktool decompiles apk, and extracts .dex files, which can further be converted to jar using Dex2Jar. Jar can be decompiled by using JD-GUI. You can see the Java code with the help of that tool. Although the similarity of decompiled code to the actual code cannot be guaranteed. There are some advanced code obfuscation tools available in the market, which mess up the code to make it difficult to decompile / understand. eg. Proguard

    0 讨论(0)
  • 2020-11-21 07:48

    There's an app for that and generally takes just a few clicks and you are done. https://github.com/Nuvolect/DeepDive-Android

    1. Select Apps, under "Installed Apps" select your app. If it is not there you can load the APK.
    2. Select "Extract APK"
    3. Select "Unpack APK"
    4. Select "Decompile with Jadx". This can take a few seconds or a few minutes depending on the speed of your device

    After that you can browse the source code, download it to another computer with elFinder or search through it using Lucene.

    In addition to Jadx it has CFR and Fernflower decompilers.

    0 讨论(0)
  • 2020-11-21 07:49

    This is an alternative description - just in case someone got stuck with the description above. Follow the steps:

    1. download apktool.bat (or apktool for Linux) and apktool_<version>.jar from http://ibotpeaches.github.io/Apktool/install/
    2. rename the jar file from above to apktool.jar and put both files in the same folder

    3. open a dos box (cmd.exe) and change into that folder; verify that a Java Environment is installed (for Linux check the notes regarding required libraries as well)
    4. Start: apktool decode [apk file]

      Intermediate result: resource files, AndroidManifest.xml

    5. unzip APK file with an unpacker of your choice

      Intermediate result: classes.dex

    6. download and extract dex2jar-0.0.9.15.zip from http://code.google.com/p/dex2jar/downloads/detail?name=dex2jar-0.0.9.15.zip&can=2&q=
    7. drag and drop classes.dex onto dex2jar.bat (or enter <path_to>\dex2jar.bat classes.dex in a DOS box; for Linux use dex2jar.sh)

      Intermediate result: classes_dex2jar.jar

    8. unpack classes_dex2jar.jar (might be optional depending on used decompiler)
    9. decompile your class files (e.g. with JD-GUI or DJ Decompiler)

      Result: source code

    Note: it is not allowed to decompile third party packages; this guide is intended to recover personal source code from an APK file only; finally, the resulting code will most likely be obfuscated

    0 讨论(0)
  • 2020-11-21 07:49

    There are a few ways to do this:

    1. Use the "Profile or Debug APK" feature in Android Studio 3.0.

      It allows you to open and explore APKs in Android Studio. Classes are decompiled into smali. Resources are not extracted and things like "Go to Definition", "Find All References" and debugging don't work without the source code (android studio 3.0 canary 9). Some additional smali features might work with smalidea.

      android-studio

      select-file

      code

    2. Use jadx.

      Jadx decompiles the code in a given APK to java source files.

      jdax-img

    3. Use apktool.

      Apktool is a command line tool which extracts resources and decompiles code into smali for a given apk. You can recompile using apktool also. Here's an example of it in action:

      $ apktool d test.apk
      I: Using Apktool 2.2.4 on test.apk
      I: Loading resource table...
      I: Decoding AndroidManifest.xml with resources...
      I: Loading resource table from file: 1.apk
      I: Regular manifest package...
      I: Decoding file-resources...
      I: Decoding values */* XMLs...
      I: Baksmaling classes.dex...
      I: Copying assets and libs...
      I: Copying unknown files...
      I: Copying original files...
      $ apktool b test
      I: Using Apktool 2.2.4 on test
      I: Checking whether sources has changed...
      I: Smaling smali folder into classes.dex...
      I: Checking whether resources has changed...
      I: Building resources...
      I: Building apk file...
      I: Copying unknown files/dir...
      
    0 讨论(0)
  • 2020-11-21 07:49

    This site https://www.apkdecompilers.com/ did it automatically.

    I tried the site mentioned in the accepted answer first but that didn't work for me.

    0 讨论(0)
提交回复
热议问题