The previous article describes how to use ant to automatically compile and package an existing Android project, which will continue to show you how to add signature information and automatically package channel packs when you pack your ant apps.
1. Add signature information:
In the project root directory to build a ant.properties file, enter the following, where the keystore password and alias password can not be specified (anti-leakage), then in the process of command execution will ask you to enter.
[HTML]View Plaincopy
- #keystore的路径, you must use a forward slash
- key.store=E:/wp_android_sample/me.key
- #keystore的密码
- #key.store.password=*****
- #alias名
- key.alias=Me
- #alias密码
- #key.alias.password=******
Running the ant release command under the project root will help you generate a signed and aligned APK, the generated apk (your_project_name-release.apk) in the bin directory
2. Automatic packaging of channel packs:
Implementing bulk cycle wrapping requires a function similar to for loops, where there is no related for loop task in the ant core package, that is, the for loop is not supported, but Ant supports third-party expansion packs to support additional features.
So we're going to download the appropriate extension package that supports the for loop. You can use the Open source Ant-contrib package. : http://ant-contrib.sourceforge.net/.
The downloaded jar files are placed into the Ant's Lib directory. Next we can package the channel package, the specific method is:
(1) First add attribute Market_channels (channel list, comma-separated) in Ant.properties file, version (application version name)
- #渠道市场列表
- market_channels=91,360,wandoujia,baidu
- #版本号
- version=1.2.1
(2) Add the following code to the Build.xml of our project:
- <!--channel Pack packaging script Ant deploy-->
- <taskdef resource="net/sf/antcontrib/antcontrib.properties">
- <classpath>
- <pathelement location="Lib/ant-contrib-1.0b3.jar"/>
- </classpath>
- </taskdef>
- <target name="Deploy">
- <foreach target="modify_manifest" list="${market_channels}" param="channel" delimiter=",">
- </foreach>
- </target>
- <target name="Modify_manifest">
- <!--plus time stamp--
- <tstampprefix= "build." >
- <formatproperty= "timesign" pattern= "yyyymmddhhmm"/>
- </tstamp>
- <replaceregexp flags="G" byline="false">
- <!--matches is android:value= "* * * * *" android:name= "Umeng_channel"-
- <regexp pattern=' android:value= "(. *)" android:name= "Umeng_channel" ' />
- <!--match and replace it with android:value= "channel name" Android:name= "Umeng_channel"-
- <substitution expression=' android:value= "${channel}" android:name= "Umeng_channel" ' />
- <!--regular expressions require matching files of Androidmanifest.xml --
- <fileset dir="" includes="Androidmanifest.xml" />
- </replaceregexp>
- <property name="out.release.file" location= "${out.absolute.dir}/${ant.project.name}_$ {channel}.apk " />
- <!--pack --
- <antcall target="release" />
- <!--output channel package to bin/out directory --
- <copy tofile="${out.absolute.dir}/out/${ant.project.name}v${version}-${channel}.apk" file ="bin/${ant.project.name}-release.apk"/>
- </target>
Running the ant deploy command at the root of the project will help you to sign the package for each channel (for the full automatic execution, the password for the KeyStore in the Ant.properties file can be specified so that you do not need to enter the password manually during execution), In the Out directory of the bin directory.
Android-ant automatically compile and pack Android projects-2----signatures and channel packs