Use Ant packaged Android app to explain--ant usage resolution

Source: Internet
Author: User
Tags file copy

The use of Ant packaged Android application specific explanation describes the process of using ant packaging, but the very many steps do not explain why, this article will be understood from the ant aspect, the next one from the APK generation process to illustrate.

The build of the APK package is the result of a series of operations, and Ant is the process of this sequence of operations. Provides a customized interface and configurable parameters for changes, which are implemented through the specified build file.

We understand some of ant's basic usage methods from the ant packaging process.

When you run ant on the command line. The default is to parse the build.xml of the current folder as the build file. The following is a version number that deletes a partial gaze:

<project name= "project name" default= "Help" > <!--the local.properties file was created and updated by the ' Android ' tool. It contains the path to the SDK. It should *not* is checked into Version Control Systems. --<property file= "local.properties"/> <property file= "ant.properties"/> <!--Import per project cus Tom build rules if present at the root of the project. This was the place to put custom intermediary targets such as:-pre-build-pre-compile-post-compile (this is typically use D for code obfuscation. Compiled code location: ${out.classes.absolute.dir} If The is not do in place, override ${out.dex.input.absolute.dir}) -post-package-post-build-pre-clean--<import file= "Custom_rules.xml" optional= "true"/> <!--import the A Ctual build file. <import file= "${sdk.dir}/tools/ant/build.xml"/>
Follow up to the tools/ant/build.xml of your SDK folder to see the complete process of ant packaging.
1. First understand several concepts, project, target, task. In a nutshell, one of your construction projects (project) divides a very multi-stage or sub-goal (target). and the realization of each stage goal. You want to provide detailed operations, such as file copy, source code compilation, these packaged operations are task (can be understood as a library function for you). In detail, each build file has a top-level label for project. As an identity. And target is the sequence of operations you want to run. Target can have very many tasks in it. So how do you determine the order in which the sequence of operations is run? In this case, project default refers to the target, which is run at the command line, which is the target that you run when you simply enter ant without any of the parameters.

And when you specify target, such as entering Ant Help on the command line. Will find the target help run from your build file. When we enter ant release, the corresponding target is as follows:

<target name= "Release" depends= "-set-release-mode,-release-obfuscation-check,-package,-post-package,- Release-prompt-for-password,-release-nosign,-release-sign,-post-build "description=" Builds the application in Release mode. " > </target>
The name and description of Target are as the name implies, and depends is the target to run or rely on before the target runs, and runs sequentially from left to right. Continue to follow-package its definition: <target name= "-package" depends= "-dex,-package-resources", respectively, the production of Dex files and resource packaging, It also defines a lot of detailed target.

The whole process is or is reserved for some empty target, such as-pre-build-pre-compile-post-package-post-build, is the end of each package compilation step before, through the Custom_ Rewrite these target in Rules.xml. Meet the requirements of customization
2. The problem of running the sequence is overcome. So how to configure the number of parameters?
(1) First in the Build.xml under Project, the property can be understood to define some variables or introduce a property file. Look at some of its properties:
The name of the Name:property, which can be referenced in the form of ${name} at Target or elsewhere
Value: A detailed value or path
File: The property file that needs to be loaded, the contents of the files appear in Key=value, such as the SDK path of sdk.dir=android defined in Local.properties
refID: Referencing the path information already defined
The local.properties of the property definition in Build.xml's own project introduces the information that Android Sdk/ndk,ant.properties needs to introduce a signature, and here's a key feature. Once a property is defined, its value cannot be changed, and the first defined value is preserved; Facilitates some custom operations during the compilation process. Add your own Framework.jar to Project.target.class.path by calling the Hide API in the previous article
(2) Import tag, attribute file: The build file to be introduced, optional: true, even if the import file does not exist, it does not stop compiling. Then Custom_rules.xml is dispensable. And ${sdk.dir}/tools/ant/build.xml is the file that defines the actual compilation step must exist
3. Some of the other tags used
(1) Define file folder path, from the samples in the Ant manual:

<path id= "Base.path" >      <pathelement path= "${classpath}"/>      <fileset dir= "Lib" >        < Include name= "**/*.jar"/>      </fileset>      <pathelement location= "Classes"/> </path>
A path that can be referenced elsewhere by refID, which contains the detailed path path pathelement and the Fileset to filter the file through include or exclude
(2) Copy task

<copy todir= "${source.absolute.dir}" >     <fileset dir= "Other source code Folders" >        <include name= "**/*.java"/ >        <include name= "**/*.aidl"/>    </fileset> </copy>
Odir: Destination folder, the source folder is defined on the fileset, and the rule contains all. java files and all aidl files. Simple as copying a single file
<copy file= "MyFile.txt" tofile= "Mycopy.txt"/>
Copy a file to a folder
<copy file= "MyFile.txt" todir= ". /some/other/dir "/>
This information can be learned by querying the ant reference manual https://ant.apache.org/manual/. Not a narrative.


The above description should be able to understand and follow up the entire ant packaged Android application process, according to their own needs to customize the operation



Use Ant packaged Android app to explain--ant usage resolution

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.