Using Ant packaged Android app--ant use resolution

Source: Internet
Author: User

The previous article, "Using Ant to pack Android apps," describes the process of using ant packaging, but many of the steps do not explain why, this article will be understood from the ant side, 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 series of operations, providing a customized interface, as well as configurable parameters for modification, which are implemented through the specified build file. We understand some of the basic uses of ant from the ant packaging process. When you execute ant on the command line, the default is to parse the build.xml of the current directory as the build file. Here is a version of the deleted part of the 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 directory to see the complete process of ant packaging.
1. First understand several concepts, project, target, task. Simply put, one of your construction projects (project) divides many stages or sub-goals (target), and each phase of the goal implementation, you have to provide specific operations, such as file replication, source code compilation, these packaged operations are task (can be understood as a library function for you). Specifically, each build file has the top-level project tag as the identifier, and target is the sequence of actions you want to perform, and the target can have a lot of tasks. So how do you determine the order in which the sequence of operations is performed? Where project's default refers to the target that is executed by defaults, that is, when you enter only ant without any parameters at the command line. When you specify target, such as entering Ant Help on the command line, the target help execution is found 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, while depends is the target that needs to be executed or relied upon before the target executes, and is executed sequentially from left to right. Continue to follow-package its definition: <target name= "-package" depends= "-dex,-package-resources", respectively, Dex file generation and resource packaging, It also defines a lot of specific target. The entire 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 to meet the requirements of customization
2. Solve the problem of execution sequence, then how to configure the parameters?
(1) First in the project under the Build.xml property, can be understood as the definition of some variables or the introduction of properties files, to see some of its attributes:
The name of the Name:property, which can be referenced in the form of ${name} at Target or elsewhere
Value: Specific values or paths
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 introduced the Android SDK/NDK, Ant.properties introduces the information required for signing; Here's a key feature is that once the property is defined, its value cannot be changed, and the first defined value is preserved, which facilitates some of the customizations that are made 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 the file directory path, from the example 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 includes the specific 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 directory" >        <include name= "**/*.java"/ >        <include name= "**/*.aidl"/>    </fileset> </copy>
Odir: Destination directory, the source directory is defined on the fileset, and the rule is to include 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 directory
<copy file= "MyFile.txt" todir= ". /some/other/dir "/>
This information can be found by querying the ant reference manual https://ant.apache.org/manual/, without describing


The above description should allow you to understand and follow up on the entire ant packaged Android application process and customize it to suit your needs.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Using Ant packaged Android app--ant use resolution

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.