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

前端 未结 27 1847
难免孤独
难免孤独 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: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...
      

提交回复
热议问题