Ant hands-on practices for Androidのbuild tools

Source: Internet
Author: User

Haven't written a blog for a long time, not half a year should also have a few months. In the work of the project encountered a lot of problems or have accumulated a lot of experience, once would like to send to the blog to leave a memorial what, do not ask for others to get some experience skills, only in years after encountering the same problem can find a record. But, maybe lazy is lazy, and work time to write a blog a bit bad (after work is easy to forget).

Because the export signature package with Eclipse often fails, or because of insufficient memory or other things do not understand the reason, the project is really a bit large, the optical library has seven or eight, and finally keep the packaging interface code can not knock a line to see the Packaging dialog box end (usually means that the export APK success ), and finally Quejinshaoliang. Under normal circumstances is about 6.8M volume, occupy more than 7M of space, but can not come out of the package will be less then some time 5.8M sometimes 6.8M, such a package run will not find the class. At the most annoying time, it's hard to hit a standard apk with a one-day package. Even if it comes out, this process is also very long, and is the Eclipse front desk, during which you can not do anything else, so it is particularly annoying, and then try to learn ant, previously used maven, on Android is still a bit inconvenient.

Watching the tutorial on the Internet also see busy tired, but found a blog to do, and finally succeeded (forget which blog address, bad consciousness), during the period also encountered several problems, but now forget.

I. Automatically call the Build.xml in the SDK directory to package

If in the main project build must every library also update out their own build.xml, and the library directory is best not to have Chinese, otherwise it will be wrong.

Use CMD to enter the library's directory, and then execute this command to automatically generate a Build.xml file for your project.

Android Update Project--path

Then execute ant release in the Build.xml of your main project and you will be able to pack it up successfully.

If you want to make a signature package, you will be able to automatically generate a signature package by writing the KeyStore information in Ant.properties.

<?XML version= "1.0" encoding= "UTF-8"?><Projectname= "Mainactivity"default= "Help">    <!--The local.properties file is created and updated by the ' Android ' tool. It contains the path to the SDK. It should *not* is checked into Version Control Systems.  -    < Propertyfile= "Local.properties" />    <!--The ant.properties file can created by.         It is only edited by the ' Android ' tool to add properties to it.         The "the" to "change some Ant specific build properties. Here is some properties want to change/update:source.dir the name of the source directory.         Default is ' src '. Out.dir the name of the output directory.         Default is ' bin '.         For other overridable properties, look at the beginning of the rules files in the SDK, at Tools/ant/build.xml Properties related to the SDK location or the project target should is updated using the ' Android ' tool with T         He ' update ' action. This file is a integral part of the build system for your application and should are checked into Version Control         Systems.  -    < Propertyfile= "Ant.properties" />    <!--If Sdk.dir is not set from one of the property file, then get it from the Android_home env var. This must is done before we load project.properties since the Proguard config can use Sdk.dir -    < PropertyEnvironment= "env" />    <condition Property= "Sdk.dir"value= "${env." Android_home} ">        <isset Property= "env." Android_home " />    </condition>    <!--The Project.Properties file is created and updated by the ' Android ' tool, as well as ADT. This contains project specific properties such as project target, and library dependencies.         Lower level build properties is stored in ant.properties (or in. classpath for Eclipse projects). This file is a integral part of the build system for your application and should are checked into Version Control Systems.  -    <loadpropertiesSrcfile= "Project.Properties" />    <!--quick check on Sdk.dir -    <failmessage= "Sdk.dir is missing.  Make sure to generate Local.properties using ' Android Update Project ' or to inject it through the android_home environment Variable. "unless= "Sdk.dir"    />    <!--Import per project custom 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-po                           St-compile (this was typically used 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 -    <Importfile= "Custom_rules.xml"Optional= "true" />    <!--Import the actual build file. To customize existing targets, there is, options:-Customize only one target:-Copy/paste the TA             Rget into this file, *before* the <import> task.         -Customize it to your needs.               -Customize the whole content of build.xml-copy/paste the content of the rules files (minus the top node)             Into this file, replacing the <import> task.         -Customize to your needs. IMPORTANT ****** *********************** In all cases must UPDA Te the value of Version-tag below to read ' custom ' instead of a integer, in order to avoid have your file be ov Erridden by tools such as "Android Update Project" -    <!--version-tag:1 -    <Importfile= "${sdk.dir}/tools/ant/build.xml" /></Project>

The Android Update Project--path command executes after you generate Build.xml

Key.store = C:/users/bvin/desktop/test.keykey.alias = Testkey.store.password = 101817key.alias.password = 101817java.encoding = UTF-8

Ant.properties is used to record key.store information.

-RELEASE-UNALIGNED.APK not zip-aligned apk

-release-unsigned.apk unsigned apk

-RELEASE.APK also signed the APK

If there is a mapping.xml file in the Prouard that has been confused, the confusion corresponding file after each build is saved

Two: Custom build.xml for extended functions

The first method has limitations, with the Build.xml file in the SDK directory so there are many unnecessary files, and you can not rename and copy the APK to a directory

A few days ago always wanted to do this, is the bin directory of the release file name and assigned to the specified directory, so I can call the test to my shared directory to test, not every time I use QQ to send him the speed and slow.

As a test, the introduction of Custom_rules.xml in Build.xml, in the custom_rules definition of a target placed behind the release, I thought that after the build.xml implementation of release will automatically come out mytest output.

I was disappointed by the result. Today I just looked at the "Ant Authority Guide" book (PDF, Lite), which says "dependencies specify what ant must do before the current target is executed," and I can see that the other targets depend on release, but the release target does not execute the target that depends on it. The mytest should be executed so that Ant will call release first and then execute mytest.

According to the idea of direct execution of Custom_rules.xml mytest results error, a little Baidu and then think about what should be missing a reference, and then in turn import this build.xml file, so you can really

<?XML version= "1.0" encoding= "UTF-8"?><Projectname= "Test"default= "">    <!--Disclaimer Sdk.dir -    < Propertyfile= "Local.properties" />        <!--Disclaimer KeyStore -     < Propertyfile= "Ant.properties" />     < PropertyEnvironment= "env" />        <condition Property= "Sdk.dir"value= "${env." Android_home} ">        <isset Property= "env." Android_home " />    </condition>        <loadpropertiesSrcfile= "Project.Properties" />    <!--quick check on Sdk.dir -    <failmessage= "Sdk.dir is missing.  Make sure to generate Local.properties using ' Android Update Project ' or to inject it through the android_home environment Variable. "unless= "Sdk.dir"    />        <Targetname= "MyTest"depends= "Release">        <Echo>Finally suc</Echo>    </Target>    <!--depends = "-release-sign" -    <Targetname= "copyapk">                <Tstamp>            <format Property= "Nowtime"pattern= "YYYYMMDD_HH.MM"/>        </Tstamp>        <Echo Level= "Info">Copyapk...${ant.properties.name}-${nowtime}</Echo>        <CopyFilesrc= "${ant.project}/bin/${ant.project.name}-release.apk"dest= "c:/users/bvin/desktop/${ant.project.name}-${nowtime}.apk"ForceOverwrite= "true" />        <Echo Level= "Info">Copy dir: "c:/users/bvin/desktop/${ant.project.name}-${nowtime}.apk"</Echo>    </Target>        <Importfile= "${sdk.dir}/tools/ant/build.xml" /></Project>

The final victory is packaged and then output finally suc

Introduced Build.xml so ant also loaded all the target inside the build.xml.

Ant hands-on practices for Androidのbuild tools

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.