Current location - Quotes Website - Signature design - How to decompile android applications and recompile, sign and optimize alignment?
How to decompile android applications and recompile, sign and optimize alignment?
First, understand why we need to decompile apk.

In most cases, you need to do this because you want to localize an excellent application; Or make a few smali modifications to achieve the desired effect (for example, add a place to make the 3G version of Nexus 7 support Wi-Fi hotspots).

Prepare the running environment and tools first.

Create a working directory, such as. \workspace\apktoolbox (take this path as an example below).

Necessary JDK:Oracle Java download, after installation, put

Apk tool for decompilation and recompilation: Google code download, download by platform (an apktool-install-

Key documents, ***4 groups. Test/shared/media/platform, which is obtained from the android source code, should be signed for different * * * user IDs (check the android:sharedUserId item in the second line of AndroidManifest.xml), and put it in. \workspace\apktoolbox\bin。

Test-no android:sharedUserId entry.

shared-Android:shared userid = Android . uid . shared

media-Android:shared userid = Android . uid . media

Platform-Android: shared userid = android.uid.system.

The signature tool, signapk.jar, is placed below. \workspace\apktoolbox\bin。

Zipalign, an alignment optimization tool (obtained from android sdk, under the tools directory), is located at. \workspace\apktoolbox\bin。

The preparatory work has been completed.

Next, we will start our work (taking localization as an example).

Put the apk to be decompiled in the. \workspace\apktoolbox\apks。

Input. \workspace\apktoolbox\bin directory, enter the following command to unpack (decompile).

apktool d..\ apks \ & ltapkfile & gt。 apk..\ apks \ & ltoutdir & gt

. \ workspace \ apktoolbox \ apks \ & lt; Outdir & gt\res (English original) and \ values directory under Values-R.

After localization, enter the following command at the command line to repackage (recompile)

apktool b..\ apks \ & ltoutdir & gt

. \ workspace \ apktoolbox \ apks \ & lt; Outdir & gt repackaged apks (unsigned and misaligned) will be generated in the \dist directory.

After repackaging, enter the following command at the command line to sign (choose the key according to the actual situation, here take the test key as an example)

Java-jar signapk . jar testkey . x509 . PEM testkey . pk8..\ apks \ & ltoutdir & gt\ dist \ & ltapkfile & gt。 apk..\ apks \ & ltapkfile & gt_signed.apk

After signing, enter the following command at the command line for alignment optimization.

zipalign -f -v 4..\ apks \ & ltapkfile & gt_signed.apk..\ apks \ & ltapkfile & gt_zipaligned.apk

& ltapkfile & gt_zipaligned.apk is the final apk we need.

accomplish

Some apks need system framework resources, otherwise there will be errors when repackaging. In this case, we just need to install the corresponding system framework (extract/system/framework/framework-res.apk from your target rom and put it in. \workspace\apktoolbox\apks)。 Enter the following command at the command line to install.

apktool if..\apks\framework-res.apk