Automated Android construction-Ant multi-channel packaging practice analysis (I)

Source: Internet
Author: User

Automated Android construction-Ant multi-channel packaging practice analysis (I)
Preface

Ant is an automated building tool with a long history. Android Developers can use it for automated building or multi-channel packaging, there are generally three apk packaging methods: Ant, Python, and Gradle. These three packaging methods have their own advantages and disadvantages. This article will introduce how to use Ant for automatic building and multi-channel Publishing.

Development Environment Window7 Ant jdk android sdk

The running environment required in mac is similar. We need to configure environment variables for Ant, jdk, and sdk. Let's take a look at what environment variables are configured in 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 preceding environment variables are configured, you can proceed to the next step? Go home. Development is not suitable for you.

First talk about the APK Build Process

The following describes the apk construction process:
1. Use aapt to generate the R. java class file
2. Use android sdk.exe to convert. aidl to a Java file.
3. Use the javac command to compile. java class files to generate class files
4. Use the dx. bat command line script provided by the android SDK to generate the classes. dex File
5. Use aapt.exe of android sdk.exe to generate a resource package file
6. Use apkBuilder. bat to generate an unsigned apk Installation File
7. Use jdk's jarsigner to sign the apk for the unsigned package
8. Use Zipalign to optimize the apk

From the above description, we can know the specific steps of the apk and the tools used. The corresponding tools can be found in the sdk. Flip it by yourself, but you will find the new sdk version, aapt is putBuild-toolsDirectory,ApkBuilder. batThe file cannot be found in the tools directory. You can go online to the next one and put it in the tools directory. To make everyone better aware of the apk build process, put an official figure:

With this figure, I believe you know how the apk is generated.

Detailed description of the build command aapt command to generate the R. java File

Example command:

Aapt package-m-J -S -I-M

Command explanation:

-F if the compiled file already exists, force override
-M stores the directory of the generated package in the directory specified by the-J Parameter
-J specifies the output directory of the generated R. java file.
-S res folder path
-A assert folder path
-I path of android. jar of a specific version of the platform
-F specifies the output of the APK file.

Aidl command generation. aidl File

Example command:

Aidl-p <framework. aidl path>-I -O <target file directory>. aidl File </Framework. aidl path>

Note:There are no spaces between commands and paths..

<Framework. aidl path> Javac command to generate the. class File

Example command:

javac -d destdir srcFile

Parameter description:
-D: Specifies the folder for storing classes.
-Bootclasspath overwrites the position of the boot class file
-Encoding: Specifies the encoding used by the source file.
-Sourcepath: Specifies the location of the input source file.

Dx command to generate the classes. dex File
Example command:
dx --dex --output classes.dex  bin/classes/  libs/

Command explanation: Compile the class file in bin/classes and the jar file in libs into the classes. dex file.

Aapt generates the resource package file resources. ap _

Command example:

Aapt package-m-J
     
      
-S
      
       
-I-A-M-F
       
      
     
Apkbuilder. bat is out of date. Use the following method:

Example command:

Java-cp
        
         
Com. android. sdklib. build. ApkBuilderMain <unsigned .apk>-v-u-z bin \ resources. ap _-f bin \ classes. dex-rf src
        
Generated by jarsigner
Example command:
Jarsigner-verbose-keystore
         
          
-Signedjar-<output signature apk path> <unsigned apk path>
          
         
The last step is to use the zipalign tool for apk Alignment Optimization.

Example command:

zipalign [-f] [-v]  infile.apk outfile.apk

The above eight steps are the apk build process. They are all implemented step by step through commands. Pay attention to what is generated in each step.

Summary

This blog post mainly introduces the apk building process in Android, and also describes the specific command operations in each step in detail. Since I don't want to heap everything together, in the next article, I will use the Ant script for automated building and multi-channel packaging. You can continue to pay attention to it.

 

</Framework. aidl path>

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.