For continuous integration of Android project construction, you need to build a set of automated compilation and packaging processes, such as building a daily system and automatically generating release files. These require us to have a deep understanding of the compilation and packaging of the android project, such as knowing what each step of the project is done and what environment and tools are needed, what is input and output.
First, assume that your system (Windows, Linux, and Mac OS are all supported. This document uses the Linux system as an example by default, but there is almost no difference in Windows) JDK and Android SDK have been installed. If not, refer to my previous blog: Build eclipse + JDK + SDK android on Ubuntu and build eclipse + JDK + SDK android on Windows.
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 ).
We focus on the following:
(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.
List the tools required in the following steps in advance:
Name |
Features |
Path in the operating system |
Aapt |
Android resource packaging Tool |
$ {Android_sdk_home}/platform-tools/APPT |
Aidl |
Android interface description language conversion to. Java file Tool |
$ {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 |
. Jar file signature Tool |
$ {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 many projects do not use aidl)
[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 a. 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] Dex 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:Alignment of the .apk file behind 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 the above details, we can implement a lot of things we want to implement. For example, the compilation process is automated. For example, we can use a script, such as batch processing in windows, bash in Linux, ant in Java, Python, Perl, and other scripting languages, even using 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 another example, we know that the android SDK is a few hundred megabytes, so we can apply the above knowledge and only keep the necessary tools to reduce the SDK to less than 10 MB. Of course, you can do a lot of things on the premise that you really understand it.
Reference recommendations:
Android project compilation process
Android uses ant to package, sign, and confuse