How to Use Ant to automatically build Android and ant to build android

Source: Internet
Author: User

How to Use Ant to automatically build Android and ant to build android

Ant is a good cross-platform build tool, especially for Java projects. It is very convenient to use it to automatically build Android projects. Generally, to build an Android project, follow these steps:

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

Use aapt to package resources required for the project;

Convert and compile the AIDL file;

Compile the Java source file and generate. class;

Convert and compress the. class file into a. dex file;

Use aapt to generate an unsigned apk package;

Use jarsigner to sign the apk package and obtain the final release package.

The implementation details required for these steps are not described in detail (most of the versions on the grid can be used). Here we mainly talk about apk packaging for multiple channels. The so-called multi-channel generally requires one of the above operations on each channel version to be released. The differences between these channels are usually some of the configuration information that can be made public, for example, the channel number, the free APP Channel Information Management Platform launched by AIBA, the service includes channel data monitoring, identification and analysis of pirated apps, developers can easily manage all the promotion channels of the APP by using the love encryption channel Monitoring Service, so that they can grasp all the information on one site. The channel monitoring platform can also help developers to immediately discover pirated apps,Protect the legitimate rights and interests of the company.Http://www.ijiami.cn/Channels

 

In this way, you can organize it into a configuration file and use the ant function to set specific channels before the process. For example:

 

[Html]View plaincopy

 

The _ PathID and _ PathName are all variables defined in the ant environment. They can be directly input from cmd or assigned values in other ways. In this way, you can directly obtain the version under this channel during subsequent compilation.

In addition, the information of all channels can be configured in xml. During the construction, the information of each channel can be directly read and assigned to the _ PathID and _ PathName mentioned above, you can use the following code to facilitate implementation (including the use of xmltask in ant. For more information, see ant ):

 

[Html]View plaincopy

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

 

[Html]View plaincopy

In addition, Ant's automated construction can also be used to protect confidential files in the asset. Here is a simple example. For example, some files in asset are visible to users but do not want to be modified by users. In this case, you can add a file verification stage in the build, first, calculate the corresponding MD5 Signature for the file to be protected, and then write the signature to the program code for compilation and construction. This signature is used for verification when the program is running, if the signature does not match, it means that the package is re-packaged after modification by the user, and then the program can perform corresponding operations, in this way, you can prevent users from re-packing and running the published Apk package in a certain program.

For Android apps, dex source code file security is the most important. Therefore, this dex source code encryption protection is actually necessary. In this aspect, we can achieve the platform of loving encryption, different types of applications have different encryption protection solutions,Http://www.ijiami.cn/appprotect_mobile_games details can be learned here:


How to copy content in ANT package to AndroidManifest file in Android

Sorry, I will not modify it from ant. I will give you a work und that I am currently using.
Use the sh script (linux/cygwin) or batchcompute (Windows) to modify the content before calling ant build.

You can directly modify the file in the script.

How does android optimize ant batch packaging?

Ant package android apps in batches

Many applications need to add application promotion statistics. If the application generates packages from different channels one by one, the efficiency is low, and the distribution channel may be mistakenly mistaken, you can use ant to generate applications in batches.
1. Add channel package information

To collect channel information, you have to add channel information somewhere in the program, and then pack different packages for different channels. Generally, you can add channel numbers to the Manifest file instead of directly writing them in the code. In this way, you can automatically modify the channel numbers in the Manifest file for different channels, and then automatically package the channel.
The Manifest file supports Meta Data tags. We recommend that you use these custom tags. For example, the following file fragment.

[Html] view plaincopyprint?
<Meta-data android: value = "000000" android: name = "CHANNEL"/>

Ii. Channel package reading
[Java] view plaincopyprint?
Public static String getChanel (Context ctx ){
String CHANNELID = "000000 ";
Try {
ApplicationInfo ai = ctx. getPackageManager (). getApplicationInfo (
Ctx. getPackageName (), PackageManager. GET_META_DATA );
Object value = ai. metaData. get ("");
If (value! = Null ){
CHANNELID = value. toString ();
}
} Catch (Exception e ){
//
}

Return CHANNELID;
}

Iii. automatic packaging implementation
The Ant compilation android program briefly introduces how to use the ant command to package android programs and add a function similar to the for loop to achieve bulk packaging, there are no related For loop tasks in the Ant core package. You need to download the corresponding extension package. You can use the open-source Ant-contrib package. : Ant-contrib.sourceforge.net /. Put the downloaded jar file to the ant lib directory.
You can add the following code to build. xml for batch packaging:

[Html] view plaincopyprint?
Taskdef resource = "net/sf/antcontrib. properties">
<Classpat... the remaining full text>

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.