How to use ant to automatically build Android version

Source: Internet
Author: User


Ant is a great cross-platform build tool, especially for Java projects, where it can be very handy to automate the construction of Android projects. In general, there are several steps to building an Android project:

Use AAPT to compile the project to generate R.java;

Use AAPT to package the resources needed for the project;

Convert and compile aidl files;

Compile the Java source file and generate the. class;

Convert and Compress. class files into. dex files;

Use AAPT packaging to generate an unsigned apk package;

Use Jarsigner to sign the APK package and get the final release package.

The implementation details required for these steps are no longer detailed (the various versions on the grid, most of which can be used), and here are the main things to say about APK packaging for multiple channels. The so-called multiple channels generally need to be published in each channel version of the above-mentioned series of operations, and the differences between these channels are often public out of some configuration information, such as channel number, love encryption launched free app channel information management platform, services including channel data monitoring, For the identification and analysis of pirated apps, developers can easily manage all of the app's promotional channels by using the Love encryption channel monitoring service, all at one stop. Channel monitoring platform can also help developers to discover pirated apps for the first time, protect the company's legitimate rights and interests. http://www.ijiami.cn/Channels

As a result, you can organize it into a single configuration file, and use ant's capabilities to set up specific channel settings before making the process, such as:

 

[HTML] view Plaincopy

    1. <replace file= "${pathsettingfile}" token= "Ant_pathid" value= "${_pathid}"/>

    2. <replace file= "${pathsettingfile}" token= "Ant_pathname" value= "${_pathname}"/>

The _pathid,_pathname are variables defined in the ant environment, which can be passed directly from CMD or otherwise assigned. This allows you to get a version of the channel directly at the subsequent compile time.

In addition, the information of all channels can be uniformly configured in one XML, in the construction of the information directly read into each channel and assigned to the above _pathid, _pathname can be easily implemented with the following code (which involves the use of xmltask in Ant, This can refer to ant's Related materials):

 

[HTML] view Plaincopy

  1. <target name= "Main" >

  2. <taskdef name= "Xmltask" classname= "Com.oopsconsultancy.xmltask.ant.XmlTask"/>

  3. <echo>Starting....</echo>

  4. <xmltask source= "Paths.xml" >

  5. <call path= "/pathlist/pathdetail[@enabled = ' true ']" target= "Build" >

  6. <param name= "_pathid" path= "Id/text ()"/>

  7. <param name= "_pathname" path= "Name/text ()"/>

  8. </call>

  9. </xmltask>

  10. </target>

The corresponding channel configuration XML is basically as follows (of course, more information can be placed in it)

 

[HTML] view Plaincopy

    1. <?xml version= "1.0"  encoding= "UTF-8"? >  

    2. <PathList>      

    3.     <pathdetail name= ""  enabled = "true" >&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;

    4.     <ID>11111</ID>   

    5.     <name>path_0</name>  

    6.    </pathdetail>  

    7.    <pathdetail name= ""  enabled= "true" >&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;

    8.     <id>22222</id>  

    9.      <name>path_1</name>  

    10.    </PathDetail>   

    11. </pathlist>  

In addition, automated builds using ant can also be used for another important purpose, protecting the asset files in the system. Here is a simple example, such as asset some of the files in the user visual, but do not want to be modified by the user, in this case, you can add a file check in the construction phase, first to protect the file to calculate the corresponding MD5 signature, and then write this signature into the program code and build, Use this signature to verify when the program is running, if the signature does not match that means that the user has been modified and then re-packaged, the program can have the appropriate action, so that the program can prevent users from the release of the APK package to re-pack and run.

For Android App,dex source file security is the most important, therefore, this Dex source encryption protection is actually necessary, in this respect, can do there is love encryption this platform, different types of applications also have different encryption protection scheme, details can be learned here:/http Www.ijiami.cn/appprotect_mobile_games

How to use ant to automatically build Android version

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.