The whole process of ant bulk packaging under Mac

Source: Internet
Author: User
Tags version control system

Because there are many channels, need bulk packaging, usually window under the packaging, but how to bulk packaging under the Mac? Actually quite troublesome, the concrete steps are as follows:

I. Preparatory work before packing

1. First make sure that your JDK version is 1.6!

2. Add a label to identify the channel under Application tag in Androidmanifest.xml:

<meta-data android:name= "Qudao" android:value= "channel"/>

3. In order for ant to support the loop function, we want to put a Ant-contrib-1.0b3.jar package on Android Sdk/tools/lib

4. The folder where the third-party jar package is placed in the project must be called Libs instead of Lib

Two. Generation and configuration of files such as Build.xml

1. The Build.xml and local.properties two files are automatically generated via the terminal (CMD) command, using the following method:

<sdk>/tools/android update project-p <project> t <target>

For example:

/users/moushou/downloads/androidsdk/tools/android Update Project-p/users/moushou/documents/workspace/helloworld- T 14

Where <sdk> for the SDK full path,<project> for the project full path,<target> for the API version.

Execution completed as follows:

When you're done, refresh your project to find two more files in the root directory of your project: Build.xml and Local.properties

The content of Local.properties is:


# This file was automatically generated by Android Tools.

# Do not modify the This file--YOUR changes'll be erased!

#

# This file must *not* is checked into Version Control Systems,

# as it contains information specific to your local configuration.


# Location of the SDK. This is a used by Ant

# for customization if using a Version Control System, please read the

# header note.

Sdk.dir=/users/moushou/downloads/androidsdk


The contents of Project.Properties are as follows:


# This file was automatically generated by Android Tools.

# Do not modify the This file--YOUR changes'll be erased!

#

# This file must is checked in Version Control Systems.

#

# to customize properties used by the Ant build system use,

# "Ant.properties", and override values to adapt the script to your

# project structure.

#proguard. config=proguard.cfg

# Project Target.

Target=google Inc.:google apis:14

Proguard.config=proguard.cfg


The directory structure of the project is as follows:

Note : Project.Properties target=googleinc.:googleapis:14 represents the version of the SDK used and can be modified manually.

2. Manually create a new file for the project named: Ant.properties, which creates the directory structure of the completed project, such as:

After creation, add the following in Ant.properties:


Key.store=<keystore>

Key.alias=<key>

Key.store.password=<keystore pwd>

Key.alias.password=<key pwd>

Market_channels=xx,yy,zz

App_version=1_0_build_0


For example:


Key.store=/users/moushou/desktop/qianming

Key.alias=meilihuaduo

Key.store.password=123456xx

Key.alias.password=123456xx

Market_channels=anzhuoshichang,jifengshichang,baiduyingyongzhongxin

App_version=1_0_build_0


which

KeyStore is the full path to the signature file.

Key.alias the private key to use for signing.

Key.store.password is the password for the private key library.

Key.alias.password is the password for the private key.

Market_channels is a channel collection.

App_version is the APK version (this field can be written according to your preference).

--------------------------------------------------------------------------------------------------

At this point, except Build.xml, the rest of the file configuration is complete.

Three. How to write Build.xml:

1. Modify the second line of the Build.xml, and modify the method as follows:

<project name= "HelloWorld" default= "Release" >

Where name is the name of your project and default is set to release.

2. Replace the value of Qudao in Androidmanifest.xml with the automatic signature package, as follows:


1 <import file= "${sdk.dir}/tools/ant/build.xml"/>

2 <property name= "Out.unaligned.dir" value= "/users/moushou/desktop/helloworld_${app_version}/"/>

3 <mkdir dir= "${out.unaligned.dir}"/>

4 <target name= "Modify_update_file" >

5 <echo>*********************** make channel ${channel}</echo>

6

7 <replaceregexp file= "Androidmanifest.xml"

8 match= ' channel '

9 replace= ' ${channel} '

Ten byline= "false"

Encoding= "Utf-8"

/>

<property name= "Out.unaligned.file" location= "${out.unaligned.dir}/helloworld_${app_version}_${channel}_and roid.apk "/>

14

</target>

16

<target name= "Make_one_channels" depends= "Savemanifest,modify_update_file,release,replacemanifest,deletebin "description=" > "description"

</target>

19

<target name= "Replacemanifest" >

<echo>*********************** replacemanifest</echo>

<delete file= "${basedir}\androidmanifest.xml"/>

<copy file= ". \temp\build\meta-inf\androidmanifest.xml "todir=" ${basedir} "encoding=" Utf-8 "/>

</target>

25

<target name= "Savemanifest" >

<echo>*********************** savemanifest</echo>

<copy file= "${basedir}\androidmanifest.xml" todir= ". \temp\build\meta-inf "encoding=" Utf-8 "/>

</target>

30

<target name= "Deletebin" >

<delete dir= "${basedir}\bin"/>

</target>

34

<taskdef name= "foreach" Classname= "Net.sf.antcontrib.logic.ForEach" classpath= "/users/moushou/downloads/ Androidsdk/tools/lib/ant-contrib-1.0b3.jar "/>

<target name= "Make_channels" >

PNS <foreach target= "make_one_channels" list= "${market_channels}" delimiter= "," param= "Channel" >

</foreach>

</target>


which

1. The value of Out.unaligned.dir is the absolute path of the APK output folder, the folder is named HelloWorld combined with App_version, APP_ Version is app_version in ant.properties

2. Out.unaligned.file location for apk final output path, apk named with HelloWorld plus app_version plus current channel plus Android mode

3. Describe the packaging process:

(1) The target of line 36th Make_channels is the ant's entry, which uses a foreach loop to call Target (line 17th) named Make_one_channels and market_ Replace each value in the channels collection with the channel

(2) The Make_one_channels target specifies the process for each package:

Savemanifest: Before packaging, copy the original androidmanifest.xml to the same level directory under the project under the temp under Build Meta-inf

Modify_update_file: Matches the channel in the Androidmanifest.xml and replaces it

Release: Automatic compilation plus signature

Replacemanifest: Delete androidmanifest.xml, copy the original androidmanifest.xml from Temp/build/meta-inf back to the project root

Deletebin: Delete bin file ( Note : This step is important, otherwise you can only play a channel apk, when doing this piece of the problem encountered)

4. The classpath in the 35th row taskdef tag is the absolute path of Ant-contrib-1.0b3.jar

Four. Use of the packaging method

Open Terminal (CMD), execute:

Cd/users/moushou/documents/workspace/helloworld

Then execute:

Ant Make_channels

At this point, the package will begin! When the build successful appears, the package succeeds! As shown in the following:


At this point you will find three more apk in your output folder, such as:


Note :1. Be sure to remove the androidmanifest.xml in Temp/build/meta-inf before each package, especially if you are packing for different items

2. Before packing, please check if the value of Qudao in Androidmanifest.xml is the channel, especially when packaging fails to re-package again, make sure to change value to channel

3. If cannot recover key error causes build Faild when packaging, check if there are any extra spaces after the Key.alias.password value in Ant.properties! Some words please remove the space!

Five. Get the channel values in your code as follows:


try {

ApplicationInfo appInfo = Getpackagemanager (). Getapplicationinfo

(Getpackagename (), packagemanager.get_meta_data);

Qudao = appInfo.metaData.getString ("Qudao");

} catch (Namenotfoundexception e) {

E.printstacktrace ();

}



The whole process of ant bulk packaging under Mac

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.