Simple ant packaging and channel number Modification

Source: Internet
Author: User

Yesterday I saw ant package on the Internet, and it was a mess on the Internet, and build. the XML file is so many things that it takes two hours to reorganize it. The steps are simple and easy to understand.

Back to the truth:

1. Ant support, you know what to install, do not know what to search,

A) Configure environment variables for Android and ant

 
Export android_home =/users/stay/desktop/develop/android-sdk-mac_x86/export path =$ {path }:$ {android_home}/platform-toolsexport path =$ {path }: $ {android_home}/toolsexport ant_home =/users/stay/desktop/develop/ANT/apache-ant-1.8.4export path =$ {path }:: {ant_home}/bin

2. I use ant loop that comes with ant, if it does not support downloading a ant-contrib-1.0b3.jar put under the SDK tool/lib package

3. generate a simple build. XML. the SDK/tool/ant has a complete build. XML, we only need to create a simple build based on it. XML. You don't need to copy it.

A) Android update project-p xxx (XXX is the project path)

MB-zhst :~ Stay $ Android update project-P/users/stay/documents/workspace/waterfallupdated local. propertiesno project name specified, using activity name 'mainactive '. if you want to change it, edit the first line of build. XML. added file/users/stay/documents/workspace/waterfall/build. xmlupdated file/users/stay/documents/workspace/waterfall/proguard-project.txtIt seems that there are sub-projects. if you want to update themplease use the -- subprojects parameter.

Now, in your project, build. xml and ant. properties are automatically generated under the root directory.

In fact, at this time, you can use ant debug or ant release to package, but you have not changed the channel number.

If you want to use ant release, you have to prepare your key.

Declare the key in ant. Properties

 
Key. Store =/users/stay/desktop/xxx. keystorekey. Store. Password = xxxkey. Alias = staykey. Alias. Password = xxx

B) Open build. xml and check it.

  
     Import per project custom build rules if present at the root of the project. this is the place to put custom intermediary targets such as:-Pre-Build-Pre-compile-post-compile (this is typically used for code obfuscation. compiled code location: $ {out. classes. absolute. dir} if this is not done in place, override $ {out. dex. input. absolute. dir})-post-package-post-Build-Pre-clean   -->     Import   file  =" custom_rules.xml "  optional  =" true " />  

The imported custom_rules.xml file does not exist in the root directory of your project. If you want to perform additional operations before packaging, such as modifying the channel, create a custom_rules.xml file in the root directory, so that the custom_rules operation will be executed during compilation.

Below is my own

 <?  XML version = "1.0" encoding = "UTF-8"  ?>  <  Project  Name  = "Custom_rules"   >      <  Taskdef  Resource  = "Net/SF/antcontrib. properties"   >         <  Classpath  >              <  Pathelement  Location  = "Lib/ant-contrib-1.0b3.jar"   />          </  Classpath  >      </  Taskdef  >      <  Target  Name = "Deploy"   >          <  Foreach  Delimiter  = ","  List  = "$ {Market_channels }"  Param  = "Channel"  Target  = "Modify_manifest"   >          </  Foreach  >     </  Target  >      <  Target  Name  = "Modify_manifest"   >         <  Replaceregexp  Flags  = "G"  Byline  = "False"  >            <  Regexp Pattern  = "Android: value = & quot; (. *) & quot; Android: Name = & quot; umeng_channel & quot ;"   />                <  Substitution  Expression  = "Android: value = & quot; $ {channel} & quot; Android: Name = & quot; umeng_channel & quot ;"   />               <  Fileset  Dir  = ""  Includes = "Androidmanifest. xml"   />          </  Replaceregexp  >          <  Property  Name  = "Out. Final. File"  Location  = "$ {APK. dir}/xxx_{channel}.apk"   />          <  Antcall  Target  = "Clean"  />          <  Antcall  Target  = "Release"   />      </  Target  >  </  Project  > 

I will explain it below

 <?  XML version = "1.0" encoding = "UTF-8"  ?>  < Project  Name  = "Custom_rules"   >  <! --  Declare ant loop. Here ant's loop function is used directly, and batch processing requires more writing.CodeAnd I am not familiar  -->      <  Taskdef  Resource  = "Net/SF/antcontrib. properties"   >          <  Classpath  >             <  Pathelement  Location  = "Lib/ant-contrib-1.0b3.jar"   />          </  Classpath  >      </  Taskdef  >  <! --  Here is equivalent to a method (meaning ant does not, can only understand =), later you can use the command line ant deploy to indicate batch packaging  -->  <! -- $ {Market_channels} must be declared in local. properties and used to separate the channel names to be packaged.  -->  <! --  For example, in my local. properties, market_channels = Google, gfan, anzhi, and mumayi are written as follows:  -->      <  Target  Name  = "Deploy"   >          <  Foreach  Delimiter  = ","  List = "$ {Market_channels }"  Param  = "Channel"  Target  = "Modify_manifest"   >          </  Foreach  >      </  Target  >  <! --  Modify the channel name in manifest. xml.  -->  <! -- Regexp pattern is a regular match. Here, double quotation marks are used as & quot; instead \  -->  <! --  Substitution expression is the channel name you want to replace  -->  <! --  After packaging, move the APK to a specified directory. You can search out. Final. File In SDK/tools/ANT/build. XML to find out where the property is used.  -->  <! --  <Property name = "out. final. file "location =" $ {APK. dir}/xxx_{channel}.apk "/>$ {APK. dir} indicates the APK directory you want to specify. xxx indicates that you want to define the APK name and $ {channel} channel number.  -->  <! -- <Antcall target = "clean"/> <antcall target = "release"/> call clean before release. Otherwise, the channel name changed in the future will not take effect.  -->      <  Target  Name  = "Modify_manifest"   >         <  Replaceregexp  Flags  = "G"  Byline  = "False"  >            < Regexp  Pattern  = "Android: value = & quot; (. *) & quot; Android: Name = & quot; umeng_channel & quot ;"   />                <  Substitution  Expression  = "Android: value = & quot; $ {channel} & quot; Android: Name = & quot; umeng_channel & quot ;"   />               <  Fileset  Dir  = "" Includes  = "Androidmanifest. xml"   />          </  Replaceregexp  >          <  Property  Name  = "Out. Final. File"  Location  = "$ {APK. dir}/xxx_{channel}.apk"   />          <  Antcall Target  = "Clean"   />          <  Antcall  Target  = "Release"   />      </  Target  >  </  Project  > 
OK, all the configurations are complete. If you want to modify other things, I will solve the problem by myself. I will not ant. I just checked it online based on my own needs, if you want to ask me what the command is, I will not.

Finally, package the command

Open the command line: ant deploy

Apks will be released.

P.s. If you have introduced other libary, if they do not have build. XML, generate one for them, same as 3.a)

 

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.