The compiler process for Android applications and the introduction to using Ant-compiled projects _android

Source: Internet
Author: User

The continued integration of the Android project requires building a compilation and packaging automation process, such as building a daily build system, automatically generating release files, and so on. All of this requires a deeper understanding of the Android project's compilation and packaging, such as knowing what each step does, what environment and tools it needs, what inputs and outputs are, and so on.

First of all, assuming that your system (Windows, Linux, Mac os) is OK, this article defaults to using Linux as an example, but there is little difference in windows that has the JDK and the Android SDK installed.
Our main concern is:
(1) What is the input of 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 online search, this is not the focus of this article.

List the tools you need in the following steps in advance, such as the table below:

Step One: Package resource files, generate R.java files
"Enter" the resource file (which is the file in the project Res), the assets file (equivalent to another resource, the Android system is not as optimized as the file in res), Androidmanifest.xml file (the package name is read from here, because the package name is required to generate the R.java file), 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_ is it), R.java files (in the Gen directory, you should be very familiar with)
Tool AAPT Tool, its path is ${android_sdk_home}/platform-tools/aapt (if you are using a Windows system, it should be written in the customary path:%android_sdk_home%\ Platform-tools\aapt.exe, same below).

Step Two: Process the Aidl file, generate the corresponding. java file (of course, there are many projects that do not use the aidl, then the process can be saved)
"Input" source file, aidl file, framework.aidl file
The. java file that corresponds to "output"
Tools Aidl Tool

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 Tool

Step Fourth: Convert the. class file into a. dex file supported by the Davik VM
"Input". class file (including Aidl generation. class file, R generated. class file, source file generated. class file), library file (. jar file)
Output. dex file
Tools Dex Tool

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

Step Sixth: Sign the unsigned. apk file
"Enter" an unsigned. apk file
The. apk file with the "output" signature
"Tools" Jarsigner

Step seventh: Align to the signed. apk file (no alignment is possible to be published to Google market)
The. apk file after the "enter" signature
The. apk file after the output is aligned
Tools Zipalign Tool

Once you know these details, you can implement a lot of things that we want to implement, such as compiling process automation, for example, we can use some kind of script, like batch processing under Windows, Bash,java under Linux, Ant,python, Perl, Even directly with Java,. NET these strong type language also can.
If you really understand the steps above and understand the nature of the compile package process, you can automate it in any way you want, which is the real "extrapolate, status quo." Another example, the streamlining of the Android SDK, we know that now the Android SDK hundreds of trillion, we can fully apply the knowledge, only the necessary tools to reduce the SDK to 10M below. Of course, you can do a lot of things, if you really understand it.

Using the compilation tool ant

1, download
This is the official download page:
http://ant.apache.org/srcdownload.cgi
My example environment below is the Ubuntu system.

2, installation
1) Decompression

Tar zxvf apache-ant-1.9.0-bin.tar.gz

2) Configure the environment

sudo vi/etc/profile
export ant_home=/home/homer/apache-maven/ant-1.9.0/
export path= $ANT _home/bin: $PATH
sudo source/etc/profile

3, verify

homer@ubuntu:~$ ant-v
Apache Ant (TM) version 1.9.0 compiled on March 5 2013 the '
default build trying. XML
Buildfile:build.xml does not exist!
Build failed

Installation Complete!


4, create the project
1 List of Android platforms

Android list targets

The output results are as follows:

2 Android command to create a project
Command format:

Copy Code code as follows:

Android Create Project--target <target-id>--name myfirstapp--path <path-to-workspace> Myfirstapp-- Activity mainactivity--package Com.example.myfirstapp

For example, create a anttest command as follows:

Copy Code code as follows:

Android Create Project--target android-3--name anttest--path/home/homer/workspace/anttest--activity ity--package Com.homer.anttest

Create the project as follows:

5, compile the project
1) Enter the project directory

Cd/home/homer/workspace/anttest

2) Check if there are build.xml files
The Build.xml file, which is used as the ant configuration file under the project root, and if not, the build is updated with the Android update command as follows:

Copy Code code as follows:
Android Update Project--target android-3--name anttest--path/home/homer/workspace/anttest

3) Ant command Compile project
In the project anttest root directory, enter the compile command:
Ant Debug

The output command information is as follows:

At this point, the bin directory will generate anttest-debug.apk files, such as the following figure:
PPPPPPPPPPPPPPPPPPPPP5

6, installation verification
1) List AVD

Android List AVD

The AVD list is as follows:

2) Start simulator

ANDROID-SDK-LINUX/TOOLS/EMULATOR-AVD AVD-1.5

3) Installation apk

ADB install bin/anttest-debug.apk 

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.