Objective
Ant is a long history of an automated build tool, Android developers can be used to automate the building, but also to achieve multi-channel packaging, about the way apk packaging generally has ant, Python, gradle Three kinds of, these three kinds of packaging methods have their advantages and disadvantages, This post first shows you how to use ant for automated builds and multi-channel publishing.
Development environment
- Window7
- Ant
- Jdk
- Android SDK
The operating environment required under the MAC system is similar, and we all need to configure the environment variables for ant, JDK, and SDK, and we can look at what the environment variables are under window:
ant_home : D:\android\apache-ant-1.9.4
java_home : C:\Program files\java\jdk1.6.0_45
android_sdk_home : D:\ANDROID\ADT-BUNDLE-WINDOWS-X86_64-20140321\SDK
PATH:%java_home%/bin;%android_sdk_home%\platform-tools;%android_sdk_home%\tools;%ant_home%\bin;
CLASSPATH :.; %java_home%\lib\dt.jar;%java_home%\tools.jar
After the above environment variable is well, you can go to the next step, do not match? Go home, development is not for you.
First say APK build process
The following is a brief description of the APK build process:
1. Generate R.java class files using AAPT
2. Use the Aidl.exe provided by the Android SDK to turn the. Aidl into a Java file
3. Compile the. Java class file by using the Javac command to generate a class file
4. Generate Classes.dex files using the Dx.bat command line script provided with the Android SDK
5. Generate a resource bundle file using the Aapt.exe provided with the Android SDK
6. Using Apkbuilder.bat to generate an unsigned apk installation file
7. Use the JDK's jarsigner to sign an unsigned package with an APK signature
8. Use the Zipalign tool to optimize the APK
We can know from the above description of the APK specific steps and the use of the tool, the corresponding tool can be found in the SDK, go through it yourself, but you will find the new SDK version, AAPT was placed in the build-tools directory, The Apkbuilder.bat file cannot be found in the Tools directory, you can go online to the next, and then put it in the tools directory. In order to let everyone know more about the APK build process, put an official picture:
With this picture, I believe you already know how the APK is generated, not much to say.
Build commands in a detailed
- AAPT command to generate R.java file
Example command:
aapt package -m -J <R.java文件夹> -S <res路径> -I <android.jar路径> -M<AndroidManifest.xml路径>
Command explanation:
-F If the compiled file already exists, Force overwrite
-M causes the directory of the generated package to be stored in the directory specified by the-J parameter
-J Specifies the output directory of the generated R.java
-S Res folder path
-A Assert folder path
The path to the Android.jar of a version of platform
-F specifically specify the output of the APK file
- Aidl command to generate the. aidl file
Example command:
aidl -p<framework.aidl路径> -I<src路径> -o<目标文件目录> .aidl文件
Note: There are no spaces for commands and Paths .
- The Javac command generates a. class file
Example command:
-d destdir srcFile
Parameter explanation:
-d Specifies the folder where the class is stored
-bootclasspath overwrite the location of the boot class file
-encoding Specifies the encoding used by the source file
-SOURCEPATH Specifies the location of the lookup input source file
- DX command generates CLASSES.DEX file
Example command:
dx--dex--outputclasses.dex bin/classes/ libs/
Command explanation: Compile the class file under Bin/classes and the jar file under Libs into a Classes.dex file
- AAPT generating a resource bundle file Resources.ap_
command example:
AAPT Package- M -j <R.Java folder> - S <Res path> - I. <Android.Jar Path> -A <Asset Path> - M<Androidmanifest.XMLPath> - F <Resources.AP_ file path>
- Apkbuilder.bat is obsolete, use the following methods
Example command:
java -cp <sdklib.jarcom.android.sdklib.build.ApkBuilderMain <未签名.apk> -v -u -z bin\resources.ap_ -f bin\classes.dex -rf src
- by Jarsigner to generate
Example command:
<keystore路径> -signedjar -<输出签名apk路径><未签名apk路径><keystore别名>
- Last step using the Zipalign tool for APK alignment optimization
Example command:
zipalign[-f][-v] <alignmentinfile.apkoutfile.apk
The 8 steps above are to implement the APK build process, all through the command to achieve step by step, pay attention to each step of the generated things.
Summary
This blog post mainly introduces the Android apk build process, also explained in detail every step of the specific command operation, because do not want to put everything together, I will be in the next article specifically using ant script for automated construction and multi-channel packaging, you can continue to focus on.
Welcome to my public number: Wwjblog
Ant multi-channel packaging practices built by Android Automation (top)