Preface:
What is APK? "Application package file"
Simply put, the compiled files and resource files are packaged together in a zip container. Let's just get to know it.
It usually contains the following directories and files:
1. META-INF \ store the signature key;
2. Res \ stores the resource files not compiled into resources. ARSC;
3. Lib \ stores the compilation code of specific software and shares library files;
4. The global configuration file of the androidmanifest. xml program, which describes the program name, version, access permission, and application call library file;
5. Main run files of classes. Dex
6. Resources. ARSC pre-compiled resources, such as binary XML.
Topic: The Chinese APK mostly modifies resources. ARSC, and you also need to modify classes. Dex. Classes. Dex is very interesting. After the. Class compiled by Java source code is compiled into a Dalvik Virtual Machine file that android can understand, a Dex is added to the classes. Dex file.
Why compile the APK?
Use the APK compilation tool to decompile the source files and resources in the APK file, process the source files and resource files, and then compile them to achieve customization and localization.
APK tool usage
To do well, you must first sharpen your tools. Let's first introduce the tool apktool for compiling AKP files. Apktool is a tool for decompiling and decompiling APK files. With this tool, we can build our own APK files.
First, we can use WinRAR to open the APK file. It seems like a common compressed package, but it is far from that simple. After WinRAR decompress the file, it seems that there is no problem to view the image, but when you view the XML file, you will find-"garbled ".
APK is a program-compiled file. It cannot be decompressed and modified. Of course, it is mainly for resources files such as images in the classes. Dex, resources. ARSC, and Res directories, which can be directly replaced without decompilation.
To modify the APK file, decompile the file first. Before decompiling, let's build a Java Runtime Environment.
I. Build a runtime environment
Run apktool, first download Java SDK 1.6, set the environment variables after installation, JDK-6u37 32-bit
[Guide] how to install and use Android SDK
Windows XP: Right-click "my computer", click "properties", select the "advanced" tab, and click "environment variables"
Windows 7: Right-click "my computer", click "Advanced System settings", and click "environment variables" at the bottom"
Under System Variables
New:
Variable name java_home
Variable value: C: \ Program Files \ Java \ jdk1.6 the path here is subject to your Java installation directory.
New:
Variable name classpath
Variable value .; % java_home % \ JRE \ Lib \ RT. jar; % java_home % \ Lib \ tools. jar; % java_home % \ Lib \ DT. jar. Do not lose the front point.
Edit PATH variable
Add the; % java_home % \ bin semicolon to the end of the path variable to separate it from existing items in the front.
Click the Start Menu, click "run", And Enter cmd. The DOS window appears.
Enter Java and javac. If the parameter prompt is displayed, the Environment setting is OK.
Refer to Java environment variable configuration
Ii. decompilation and recompilation
Let's take a look at apktools' apktoolpackages with 3 files, aapt.exe; apktool. BAT; apktool. Jar
These three files can be conveniently called in the C: \ Windows directory.
You can create an APK file folder under the C drive to facilitate operations, and put the modified APK file and the system framework framework-res.apk together. If there is a secondary framework, you need to put it in (if it is unclear, you can put all the APK under the system/framework ).
Run and Enter cmd to open the DOS window. Enter the command to enter the new APK folder.
CD \
CD APK
C: \ APK>
1. Install the framework
Apktool if framework-res.apk
After completion, I: framework installed to: C: \ Documents ents and Settings \ Administrator \ apktool \ framework \ 1.apk are displayed.
Apktool already contains a standard framework. Most apks do not need to be installed when unpacking, but some manufacturers (such as Samsung and HTC) use their own framework files, if you want to modify the system file in the mobile phone system/APP, the framework must be loaded; otherwise, an error will occur during the re-compilation. Frame file framework-res.apk in the mobile system/framework/, all APK files under this folder should be loaded (generally 1 to 2 ). Huawei u8825d also has a secondary framework, but it is generally useless. A file named 2.apk is generated in the example of a secondary framework.
The following example shows how to modify systemui.apk.
2. decompilation command
Apktool D systemui.apk
The systemui directory will be generated under the current directory, and the decompiled file will be here. The directory name can be customized,
For example, apktool D systemui.apk 123 123 is used to generate a directory.
3. decompilation command
Apktool B systemui 456.apk
Compile the systemuidirectory and generate the 456.apk file. The name is customized.
Token has been generated 456.apk for the compiled file, WinRAR opened with the original file found that lack of META-INF directory, this directory contains APK signature file, not signed program, the system will not be installed. Only programs with the same signature can be replaced and upgraded.
In order not to break the signature file, we use WinRAR to open the original APK and the modified APK (do not extract it), drag the resources. ARSC file back to the original APK window to overwrite the source file, and select storage in compression mode. Drag classes. Dex back to overwrite, and select the standard compression mode. If you have modified images and other resource files, you can drag the res folder back to overwrite the files, and close WinRAR to complete the APK modification.
Supplement: Generally, you can delete the res directory and drag the processed res directory to the original APK in storage mode..9.pngThe format is special. It will be compiled by aapt and cannot be replaced at will. In addition, do not replace "androidmanifest. xml" after decompilation. Otherwise, errors may occur.
Appendix: Why is the signature required?
Each application has a unique and valid ID. The signature ensures the consistency of software upgrades. applications with the same signature can overwrite the installation, inconsistent signatures cannot share usage data and overwrite the installation. This prevents tampering and protects the developer's interests. However, the signature can only be detected and cannot be modified.
3. zipalign Optimization
Using zipalign to optimize your APK file can reduce the usage of running Memory RAM.
If you have downloaded Android SDK tools, the file is located in the Android-SDK-Windows \ tools directory.
Command Format
Zipalign.exe-V 4 your APK File
Parameter V: Detailed output. Parameter 4: The alignment is 4 bytes.
Zipalign can ensure that uncompressed data in the APK file is aligned on the 4-byte boundary, so that the Android system can achieve high performance in reading resources, thus reducing RAM usage, however, the file size is generally increased.
If you sign the APK, zipalign can be optimized only after the signature.
4. Version selection and tool download
There are many integrated tools on the Internet that can be reversed, re-edited, signed, and optimized, which is quite convenient. However, understanding the command line mode will lay a good foundation for us and find the cause of errors. In particular, the command line mode is recommended for compiling the framework-res.apk framework.
If integrated tools are used, you can replace aapt.exe and apktool. jar with the latest version. Generally, there is no problem. Tip: The system APK does not need to be signed by itself. If you replace it with WinRAR, the original file signature can be retained. This is a type that only recognizes signatures and does not recognize people.
The Decompilation is not necessarily a guarantee of success. The framework and system files provided by Huawei are a bit problematic. You can find the modifications that can be run and modify them. Of course, there is a high chance of problems. We recommend that you use tools such as bcompare To Compare file differences, which is quite convenient.
There are many versions of apktool on the Internet. I was dizzy when I was looking for it. No one said that this product was originally available on the official website. The latest version of X is 1.5, and the most popular version on the internet is 1.43.
Apktool --- xda Forum address: Google address
Aapt.exe and zipalign.exe are built-in Android SDK tools. You can update the official version or download the modified version from the xda forum. (The modified version is almost 10 times the original version)
Appendix: odex "optimized Dalvik executable"
Classes. Dex is the key execution file in the APK file ,"Odex"To speed up the system boot process and pre-load part of application data, it is to work out and optimize it into a. odex file in advance, and delete the classes. Dex file in the original APK.
System/APP/phone.apk
System/APP/phone. odex
The example shows that phone.apk has a. odex file of the same name, which indicates that the life of this APK is incomplete. To compile this example, you must first use the tool to convert phone.odexback to classes.dexand integrate phone.apk with the complete phone. APK file.
"Odex" is common in official Rom, and Huawei u8825d does not need this step, so the APK merge process is omitted in this article.
Restore the detached. odex file to classes. DEX and put it back into the APK file. This process is called"Deodex". It can be compiled normally only after it is a complete APK file.
Deodex tool smali and baksmali
Command Line deodex
Manually deodexing (Windows/Linux/OSX)
Take your phone.apk and phone. odex as an example.
Create a non-Chinese directory on the computer and copy all the files in the/system/framework on the mobile phone, including the APK and jar files. Because deodex requires the system framework, but you only need five or six of them, but it is too troublesome to remember the names. Baksmali. jar and smali. jar are also copied.
Step 1Java-jar baksmali. jar-X phone. odexThe out directory is generated by default. Many tutorials on the Internet are like this "baksmali-1.2.2.jar", I thought-1.2.2 is the parameter is actually a version number, it is more convenient to change him to baksmali. jar.
Step 2Java-jar smali. jar out-O classes. DexThe-O parameter is followed by a custom name. If the-O parameter is not available, the out. Dex is generated by default.
Then, drag classes.dexinto the phone.apk with disability, select the storage format, and complete zipalin processing. You naturally know how to do the rest.
When deodexing pre-ics odex files, you must use the new -- API-level/-A option to specify the API level
Attached dex2jar Tool
Command Line dex2jar [classes. Dex] Generate classes. Dex. dex2jar. jar in the directory where classes. Dex is located JD-Gui Open classes. Dex. dex2jar. jar in JD-Gui to view the source code. |
See Android Power User: what are odex, deodex, and zipalign?
What do "odex" and "deodex" mean? The all inclusive explanation
General information about odex files
My application environment XP SP3, jdk1.6, Huawei u8825d (4.0.4)
This article is from the "same" blog, please be sure to keep this source http://yiyangde7.blog.51cto.com/392692/1068217