"Go" Android program compilation process

Source: Internet
Author: User

Many people now want to automate the compilation and packaging of Android projects, such as building a daily build system, generating release files automatically, and so on. All of this requires an in-depth understanding of the compilation and packaging of Android engineering, at least knowing what it does every step of the time, what environment and tools are needed, what the inputs and outputs are. So let's dig into the details of the Android build process.

First of all, we assume that your system (what system is OK, not limited to Linux or Windows system, of course, I use the Linux system here by default for example, but there is little difference in Windows) has installed the JDK and Android SDK. Assuming that your Android SDK path is Android_sdk_home, the Android OS version you want to compile is android_os_version (such as android-1.6, android-8, android-10, etc.).

Our main concern is (1) What is the input to this process? (2) What is the output of this process? (3) What tools are used in this process? As for what parameters to use, you can go to see the corresponding command of the Help file, or on-line search, this is not the focus of this article.

The tools mentioned in the steps are shown in the following table:

name features introduction paths in the operating system
aapt ANDROID Resource Pack tool ${android_sdk_home}/platform-tools/appt
aidl ANDROID Interface Description Language tool for conversion to. java files ${android_sdk_home}/platform-tools/aidl
javac Java Compiler ${jdk_home}/javac or/usr/bin/javac
Dex Convert. class files to. dex files that Davik VMs can identify ${ANDROID_SDK_HOME}/PLATFORM-TOOLS/DX
apkbuilder build apk package ${android_sdk_home}/tools/opkbuilder
jarsigner . jar File Signature Tool ${jdk_home}/jarsigner or/usr/bin/jarsigner
zipalign bytecode alignment tool ${android_sdk_home}/tools/zipalign

First step: Package The resource file, generate the R.java file
The "Input" resource file (which is the file in res in the project), the assets file (which is equivalent to another resource, the Android system does not optimize it as it does for files in res), Androidmanifest.xml file (the package name is read from here, because the build R.java file requires the package name), the Android base Class library (Android.jar file)
"Output" packaged resources (generally in the Android Project Bin directory can see a file called Resources.ap_), R.java files (in the Gen directory, you should be familiar with)
The "Tools" AAPT tool, its path in ${android_sdk_home}/platform-tools/aapt (if you're using a Windows system, by convention the path should be written like this:%android_sdk_home%\ Platform-tools\aapt.exe, hereinafter).

The second step: Process the Aidl file, generate the corresponding. java files (of course, there are many projects do not use the aidl, then this process can be saved)
"Input" source files, aidl files, framework.aidl files
"Output" corresponding to the. java file
Tools Aidl Tools

Step three: Compile the Java file and generate the corresponding. class file
"Input" source files (including R.java and aidl generated. java files), library files (. jar files)
"Output". class file
Tools Javac Tools

Fourth step: Convert. class files to. dex files supported by the Davik VM
"Input". class files (including Aidl. class files, R generated. class files,. class files generated by source files), library files (. jar files)
"Output". dex File
Tools Javac Tools

Fifth step: Package to generate an unsigned. apk file
"Enter" the packaged resource file, the packaged class file (. dex file), the Libs file (including the. So file, of course, many projects do not have such a file, if you do not use C + + development)
"Output" unsigned. apk file
Tools Apkbuilder Tools

Sixth step: Sign the unsigned. apk file
"Enter" unsigned. apk file
The "output" signature of the. apk file
"Tools" Jarsigner

Seventh Step: alignment of the signed. apk file (no alignment is posted to Google Market)
"Enter" after signing the. apk file
The. apk file after the "output" is aligned
Tools Zipalign Tools

Knowing these details, we can achieve a lot of what we want to achieve, such as: Automation , we can use some kind of script, like the batch processing under Windows, Bash,java under Linux, Ant,python, Perl, such as the scripting language, Even the strongly typed languages of Java and. NET are also available. If you really understand the steps above and understand the nature of the process of compiling the package, you can automate it in any way you want, which is the real "extrapolate, Status quo". For example, the streamlining of the Android SDK , you know, now the Android SDK hundreds of trillion, we can fully apply the above knowledge, only the necessary tools to keep the SDK reduced to 10M below. Of course, you can do a lot of things, if you really understand it.

Original address

"Go" Android program compilation process

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.