Android-ant automatically compile and pack Android projects-2----signatures and channel packs

Source: Internet
Author: User

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
    1. #keystore的路径, you must use a forward slash
    2. key.store=E:/wp_android_sample/me.key
    3. #keystore的密码
    4. #key.store.password=*****
    5. #alias名
    6. key.alias=Me
    7. #alias密码
    8. #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)

    1. #渠道市场列表
    2. market_channels=91,360,wandoujia,baidu
    3. #版本号
    4. version=1.2.1

(2) Add the following code to the Build.xml of our project:

  1. <!--channel Pack packaging script Ant deploy-->
  2. <taskdef resource="net/sf/antcontrib/antcontrib.properties">
  3. <classpath>
  4. <pathelement location="Lib/ant-contrib-1.0b3.jar"/>
  5. </classpath>
  6. </taskdef>
  7. <target name="Deploy">
  8. <foreach target="modify_manifest" list="${market_channels}" param="channel" delimiter=",">
  9. </foreach>
  10. </target>
  11. <target name="Modify_manifest">
  12. <!--plus time stamp--
  13. <tstampprefix= "build." >
  14. <formatproperty= "timesign" pattern= "yyyymmddhhmm"/>
  15. </tstamp>
  16. <replaceregexp flags="G" byline="false">
  17. <!--matches is android:value= "* * * * *" android:name= "Umeng_channel"-
  18. <regexp pattern=' android:value= "(. *)" android:name= "Umeng_channel" ' />
  19. <!--match and replace it with android:value= "channel name" Android:name= "Umeng_channel"-
  20. <substitution expression=' android:value= "${channel}" android:name= "Umeng_channel" ' />
  21. <!--regular expressions require matching files of Androidmanifest.xml --
  22. <fileset dir="" includes="Androidmanifest.xml" />
  23. </replaceregexp>
  24. <property name="out.release.file" location= "${out.absolute.dir}/${ant.project.name}_$ {channel}.apk " />
  25. <!--pack --
  26. <antcall target="release" />
  27. <!--output channel package to bin/out directory --
  28. <copy tofile="${out.absolute.dir}/out/${ant.project.name}v${version}-${channel}.apk" file ="bin/${ant.project.name}-release.apk"/>
  29. </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

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.