Android project compilation process

Source: Internet
Author: User

Nowadays, many people want to automate the compilation and packaging of Android projects, such as building a daily system and generating release files automatically. We need to have an in-depth understanding of the compilation and packaging of the android project. At least we need to know what each step of the android project has done and what environment and tools are needed, what is input and output. Then we can explore the details in the android compilation process.

First of all, let's assume that your system (which can be used on any system, but not limited to Linux or Windows systems). Of course, here I will use the Linux system as an example by default, but there is almost no difference in Windows) JDK and Android SDK have been installed. Assume that the path of your android SDK is android_sdk_home. The Android OS version you want to compile is android_ OS _version (for example, Android-1.6, Android-8, and Android-10 ).

What we focus on is(1) What is input in this process? (2) What is the output of this process? (3) what tools are used in this process?As for the parameters used, you can view the help files of the corresponding commands or search for them online. This is not the focus of this article.

The tools mentioned in the steps are as follows:

name function introduction path in the operating system
aapt Android resource packaging tool $ {android_sdk_home}/platform-tools/APPT
aidl tool for converting the android Interface Description Language to A. Java file $ {android_sdk_home}/platform-tools/aidl
javac Java compiler $ {jdk_home}/javac or/usr/bin/javac
Dex convert the. Class file to a. Dex file that can be recognized by davik VM $ {android_sdk_home}/platform-tools/DX
apkbuilder Generate an APK package $ {android_sdk_home}/tools/opkbuilder
jarsigner signature tool for. Jar files $ {jdk_home}/jarsigner or/usr/bin/jarsigner
zipalign bytecode alignment tool $ {android_sdk_home}/tools/zipalign

Step 1: Package the resource file and generate the R. Java File
[Input] resource file (the file in res in the project), assets file (equivalent to another resource, this resource Android system does not optimize it like the file in RES), and androidmanifest. XML file (the package name is read from here, because the R. java file requires package name), Android basic library (Android. JAR file)
[Output] package resources (generally, a package named resources is displayed in the bin directory of the android project. AP _ file), R. java file (in the gen directory, you should be familiar with it)
[Tool] aapt tool. Its path is $ {android_sdk_home}/platform-tools/aapt. (If you are using a Windows system, you should write the path as follows: % android_sdk_home % \ platform-tools \ aapt.exe, the same below ).

Step 2: process the aidl file and generate the corresponding. Java file (of course, this process can be saved if aidl is not used in many projects)
[Input] source code file, aidl file, and framework. aidl File
[Output] corresponding. Java File
[Tool] aidl Tool

Step 3: Compile the Java file and generate the corresponding. Class file.
[Input] source code file (including the. Java file generated by R. Java and aidl) and library file (. jar file)
[Output]. Class File
[Tool] javac Tool

Step 4: Convert the. Class file to the. Dex file supported by davik VM.
[Input]. Class file (including. Class file generated by aidl,. Class file generated by R,. Class file generated by source file), library file (. jar file)
[Output]. Dex File
[Tool] javac Tool

Step 5: Package the unsigned .apk File
[Input] The package resource file and the package class file (. dex files), Libs files (including. so files, of course, many projects do not have such files, if you do not use C/C ++ for development)
Export the unsigned .apk File
[Tool] apkbuilder Tool

Step 6: sign the unsigned .apk File
Enter the unsigned .apk File
Export the .apk file with the signature
[Tool] jarsigner

Step 7: Align the .apk file after the signature (the file cannot be published to Google market without alignment)
Enter the .apk file behind the token.
The. APK file behind the outputs
[Tool] zipalign Tool

After knowing these details, we can implement many things we want to implement, such:Automation, We can use some script, such as Windows batch processing, Linux bash, Java ant, Python, Perl, and other scripting languages, or even directly use Java ,. net.If you really understand the above steps and understand the nature of the compilation and packaging process, you can automate it in any way you want, ".For example,Simplified Android SDKAs you know, the android SDK is currently running for several hundred megabytes. We can apply the above knowledge and only keep the necessary tools to streamline the SDK to less than 10 MB. Of course, you can do a lot of things on the premise that you really understand it.

Related Article

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.