Android Development Learning Summary (vi)--APK anti-compilation

Source: Internet
Author: User

Learn and develop Android apps for a while, write a blog today summarizing Android apk file decompile. We know that after Android app development is complete, we will eventually package the app into an apk file and then let the user download it from the phone or tablet to install it. Under normal circumstances, after the Android app is packaged as an apk, it is no longer possible to see the resource files and code used to develop the app. But we have provided some tools on the Web, or we can decompile the APK, and after the APK is compiled, we can see the resource files (Pictures), layout, style, relevant implementation code, etc. that are used to develop the application. APK anti-compilation is also a useful skill in Android development, when we are interested in the development of good applications, we can use this technology to the other people packaged apk to decompile, and then can see what we are interested in, (Note: Anti-compilation is not to let developers go to an application to solve the heavy load of what, the main purpose is to promote the developers to learn, learn from good code, improve the level of self-development. here's how to decompile an apk.

First, prepare the necessary tools

工欲善其事, its prerequisite, first of all we need to download the relevant tools needed to decompile the APK

1.1. Using Tools
    1. Apktool (resource file acquisition)
    2. Dex2jar (source file acquisition)
    3. Jd-gui (Source view)
1.2. Introduction of tools

Apktool

Function: Resource file gets, can extract picture file and layout file for use view

Dex2jar

Role: Decompile the apk into Java source code (Classes.dex into a jar file)

Jd-gui

Role: View the apk in the Classes.dex converted into a jar file, namely the source file

1.3 Tools Download

Apktool:https://bitbucket.org/ibotpeaches/apktool/downloads

  

Download and then get a jar file as shown

  

dex2jar:http://sourceforge.net/projects/dex2jar/files/

  

  

After the download is complete, get a compressed package as shown

  

jd-gui:http://jd.benow.ca/

  

After the download is complete, get a compressed package as shown:

  

To this, the need to use the 3 related tools are downloaded, here to explain the Jd-gui download, I from the official website click on the download will often appear as shown in the question

  

But more than a few times can be downloaded, so if you have encountered this problem friends may wish to try several times, or download Jd-gui,jd-gui from somewhere else is a necessary tool for Java development, it is very convenient to use it to decompile the class Java source code, Search on the Internet generally can be downloaded to, but the version is not necessarily the latest.

Second, the APK anti-compilation process

In order to facilitate the anti-compilation, we have the above downloaded 3 tools unified into a folder, for example:

  

Then extract the "Dex2jar-2.0.zip" and "Jd-gui-windows-1.3.0.zip" separately into the current folder, as shown in:

  

2.1, using Apktool Anti-compilation apk to get pictures, XML configuration, language resources and other files

Enter the cmd command line as follows:

  

Switch to the directory where the above 3 tools are located, such as: E:\AndroidDevelopTool\Android Anti-compilation toolkit

  

The next thing we do is run the Apktool_2.0.1.jar jar file to decompile the apk file, and in Java, the command to run the executable jar package is:

Java-jar jar package name. jar

Use the following command to run the Apktool_2.0.1.jar anti-compilation mmts-release-1.0.2.apk

Java-jar Apktool_2.0.1.jar d-f E:\AndroidDevelopTool\Android anti-compilation toolkit \ Test Apk\mmts-release-1.0.2.apk-o MMTS

This command is to launch the Apktool_2.0.1.jar will be located in the "E:\AndroidDevelopTool\Android Anti-compilation toolkit \ Test Apk\" directory under the "mmts-release-1.0.2.apk" This apk anti-compilation, The resulting file is then stored in a "MMTS" folder in the current directory (the directory where Apktool_2.0.1.jar is located, which is the E:\AndroidDevelopTool\Android Anti-compilation Toolkit directory). The name of this folder can be taken casually, like to call anything.

To perform an anti-compilation operation:

  

After a successful decompile, a MMTS folder is generated under the current directory (E:\AndroidDevelopTool\Android), and the Mmts file is generated after the anti-compilation, as shown in:

  

Open the Mmts folder and you can see the resulting file as shown in the anti-compilation:

  

In the generated files and folders, we are concerned about the "res" folder and the Androidmanifest.xml file, open the Res folder, there is something we want to see, as shown in:

  

  

  

  

To see which XML file to open with a text editor to see it, anyway, you can see it all. The above is the process of using the Apktool tool to decompile an apk to get pictures, XML configuration, language resources and other files.

2.2. Use Dex2jar anti-compilation apk to get Java source code

Change the apk suffix name to be deserialized to. rar or. zip, and extract the Classes.dex file (which is the Java file compiled and then packaged by the DX tool) as shown in:

  

Put the acquired classes.dex into the previously extracted tool "dex2jar-2.0" folder, as shown in:

  

At the command line, navigate to the directory where the Dex2jar.bat is located, and enter "D2j-dex2jar classes.dex" for the following results:

  

After the command execution is complete, the generated jar file is visible in the current directory as shown in:

  

After you get the Classes-dex2jar.jar file from the Classes.dex, you can use the "Jd-gui" tool to decompile the class file into Java source code.

  

You can see the source code by opening Classes-dex2jar.jar with Jd-gui, as shown in:

  

Jd-gui Although the class can be recompiled to Java source code, but for some of the confused class, the effect of anti-compilation is not so ideal, the confused class after the anti-compilation ( class file name and the inside of the method name will be a, B, C.... Style name):

  

The above steps are my own practice after the step-by-step arrangement, compared to do should not have too much problem.

Three, apk anti-compilation note 3.1, Apktool version is too old to cause the problem of anti-compilation failure

I've used apktool before. Some old versions of this tool found that anti-compilation was always unsuccessful and the following error occurred when performing the anti-compilation:

Exception in thread ' main ' brut.androlib.AndrolibException:Could not decode ARSC file

  

This problem is due to the Apktool version is too low, and the solution to this problem is to use the latest version of Apktool, the latest version of: Https://bitbucket.org/iBotPeaches/apktool/downloads

3.2. Apktool "Input file is not found or is not readable" error executing the anti-compilation command

This problem is due to the Apktool upgrade to more than 2.0 when the mode of use has been replaced by:Apktool D [-S]-f <apkPath>-o <folderPath>

Okay, so much for the anti-compilation apk.
Finally, to share with you the three related tools I downloaded: Http://pan.baidu.com/s/1jGKSQyU

Android Development Learning Summary (vi)--APK anti-compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.