Decompile android apk and androidapk in linux

Source: Internet
Author: User

Decompile android apk and androidapk in linux

My system is ubuntu12.04

1. required tools

1) apktool: decompile the resource files and layout settings files required by the apk,

: Https://code.google.com/p/android-apktool/downloads/list

Download the apktool1.5.2.tar.bz2 and apktool-install-linux-r05-ibot.tar.bz2 files, and put the decompressed files in the same folder.


2) dex2jar. function: decompile the jar file, that is, the bytecode of the apk source file,

: Http://code.google.com/p/dex2jar/downloads/list


3) jdgui. function: view the jar file decompiled by dex2jar. You can use this tool to view the java source code corresponding to the bytecode. This is not found on the official website, and then download it on the Internet, but it has been used in experiments. Click Open, as shown in:



2. decompilation Process
1) decompile the contributed source file
Use the apktool tool to go to the directory where apktool is located and run the following command:
./Apktool d./xxx.apk (path of the apk)

D Indicates decode. A directory named xxx is generated under the current directory, which contains various decompiled resource files. res indicates the resource file, smali indicates the source code, but it is a bytecode, cannot be viewed directly.

Take my experiment as an example, as shown in:


In this case, an app-debug directory is generated under the current directory.


2) decompilation of source code
A)because the APK file is actually a compressed file generated by zipping, change xxx.apk file to xxx.zip file first and decompress it.
B) enter the decompressed directory. There is a classes. dex file, which is compiled by the java file and then packaged by the dx tool. The source code is included in this file.
C) copy the classes. dex file generated in the previous step to the root directory of the dex2jar tool, and decompile it using the following command:
./Dex2jar. sh d classes. dex
A classes_dex2jar.jar file is generated in the current directory.

D) Click to open the jdgui tool. This is a graphical tool. Open the classes_dex2jar.jar File above and you will see the source code of the apk.

My experiments are as follows:


The source code and decompiled code are compared as follows (the white is the decompiled content, and the black is the original content ):




Compile LINUX software into an android APK

Although android is based on linux, they are not Binary compatible.
Android runs a qemu-based Virtual Machine in linux and Java Virtual Machine in the virtual machine. Android APIs are mainly java, so android does not support J2sejava.

Therefore, a casual linux program code cannot be compiled into android software.

If you want to run python perl or shall scripts on your android phone, you can use a dedicated terminal on android.

In linux, locate the android-apk folder in the command line and enter the following command: java-jar apktooljar d androidapk,

The compiled command in linux should also be javac

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.