Cygwin a simulated Linux environment for ant Bulk Packaging

Source: Internet
Author: User
Tags version control system

Operating environment: Windows7 + Cygwin + ant

The first type: there is source code

This method is relatively simple. Take advantage of ant packaging.
The direct shell script modifies the file that configures the channel number.
We are currently using the Umeng. In the Androidmanifest.xml.
Provides a simple script to modify the channel number.

Configuration:

1. Environment variable configuration:

(1) cd~ or cd/home into the user directory

where the. bash_profile file is a configuration file.

(2) Enter Cat. Bash_profile View the file

  

It is configured with NDK path, ant path, SDK related path, can also be written as export path=/cygdrive/d/androiduitil/adt/adt/sdk/tools:{$PATH} style, Start cygdrive represents a disk in Cygwin.

2. Project file Configuration "placed in the project root directory, with the SRC directory sibling"

(1) Ant.properties file

# This file was used to overridedefaultvalues used by the Ant build system.## This file must is checked in Version Control Systems, as it is# integral to th E build system of your project.# this file was only used by the Ant script.# you can use ThisTo overridedefaultvalues such as#' Source.dir ' forThe location of your Java source folder and#' Out.dir ' forThe location of your output folder.# your can also use it define how the release builds is signed by declaring# the F Ollowing properties:#' Key.store ' forThe location of your KeyStore and#' Key.alias ' forThe name of the key to use.# the password would be asked during the build' Release 'Target.key.store="Signature file absolute path" Key.store.password="Signature password" Key.alias="Alias" Key.alias.password= "Signature Password"

(2) Local.properties file

 This file--YOUR changes'll be erased!  *not* be checked into Version Control systems,# as it contains information specific to your local Configurati on.# location of the SDK. This was only used by ant# for customization if using a Version Control System, please read the# header note.sdk.dir = "SDK Absolute path"

(3) Build.xml file

<?xml version= "1.0" encoding= "UTF-8"? ><project name= "" Project Name ""default= "Help" > <!--the local.properties file was created and updated by the ' Android 'tool. It contains the path to the SDK. It should*not*Be checked to Version Control Systems.--<property file= "local.properties"/> <!--The ant.properties file can created by. It 's only edited by the' Android 'tool to add properties to it.         The "the" to "change some Ant specific build properties. Here is some properties want to change/Update:source.dir The name of the source directory. Default is' SRC '. Out.dir the name of the output directory. Default is' Bin '. For other overridable properties, look at the beginning of the rules files in the SDK, at Tools/ant/Build.xml Properties related to the SDK location or the project target should be updated using the ' Android ' tool with the ' Update 'action. This file is a integral part of the build system foryour application and should is checked into Version Control Systems. --<property file= "ant.properties"/> <!--ifSdk.dir was wasn't set from one of the property file, then get it from the Android_home env var. This must is done before we load project.properties since the Proguard config can use Sdk.dir--<property environment= "env"/> <condition property= "sdk.dir. value=" ${env. Android_home} "> <isset property=" env. Android_home "/> </condition> <!--The project.properties file is created and updated by the ' Android 'tool, as well as ADT. This contains project specific properties such as project target, and library dependencies. Lower level build properties is stored in ant.properties (or in. Classpath forEclipse projects). This file is a integral part of the build system foryour application and should is checked into Version Control Systems.--<loadproperties srcfile= "Project.Properties"/> <!--quick check on Sdk.dir-<Fail Message= "Sdk.dir is missing.  Make sure to generate Local.properties using ' Android Update Project ' or to inject it through the android_home environment Variable. "unless= "Sdk.dir"/> <!--Import per project custom build rulesifPresent at the root of the project. This was the place to put custom intermediary targets such as:-pre-Build-pre-Compile-post-compile (this is typically used forcode obfuscation. Compiled code location: ${out.classes.absolute.dir} If ThisIs does not do in place, override ${out.dex.input.absolute.dir})-post- Package-post-Build-pre- Clean-<ImportFile= "Custom_rules.xml" optional= "true"/> <!--Import the actual build file. To customize existing targets, there is and options:-Customize only one target:-Copy/paste the target into ThisFile, *before* the<Import>task. -customize it to your needs. -Customize The whole content of Build.xml-copy/Paste the content of the rules files (minus the top node) into Thisfile, replacing the <Import>task. -customize to your needs. IMPORTANT ****** ***********************In all cases must update the value of version-tag below to read ' custom 'instead of an integers, in order to avoid have your file is overridden by tools such as"Android Update Project"-<!--Version-tag:1-<ImportFile= "${sdk.dir}/tools/ant/build.xml"/></project>

3. Channel List file Channel.data

4. Writing the shell script apklist.sh file

5. Execute shell Script

Go to the directory where the apklist.sh file is located, execute./apklist.sh, start bulk packaging

The second type: no source

Because we use love encryption, so we can only use this way.
Now that we have fewer channels, we are adopting the apktool approach.
First step: Anti-compilation

Java-jar Apktool.jar D com.hiwifi.hiwifi_20140801181424.apk

Step two: Modify the channel number

Sed-i. Bak ' 145s/.*/<meta-data android:name= "Umeng_channel" android:value= "' ${channel} '" \/>/'  

Step Three: Recompile

Java-jar Apktool.jar b com.hiwifi.hiwifi_20140801181424 com.hiwifi.hiwifi_lenovo.apk

I encountered the following error while recompiling:

I:checking whether sources has changed ... I:checking whether resources has changed ... I:building Resources ... Exception in thread "main" brut.androlib.AndrolibException:brut.androlib.AndrolibException: Brut.common.BrutException:could not EXEC command: [AAPT, P,--min-sdk-version, one,--target-sdk-version, A, F,/var/fol Ders/7r/ghlhnsm56fn9d3zwwmznrh9w0000gn/t/apktool4414016803544356394.tmp, 0, ARSC,-I,/users/shunpingliu/library/ apktool/framework/1.apk,-S,/users/shunpingliu/greensoftware/apktool/com.hiwifi.hiwifi_20140801181424/res,-M,/ Users/shunpingliu/greensoftware/apktool/com.hiwifi.hiwifi_20140801181424/androidmanifest.xml]at Brut.androlib.Androlib.buildResourcesFull (androlib.java:358) at Brut.androlib.Androlib.buildResources ( androlib.java:283) at Brut.androlib.Androlib.build (androlib.java:206) at Brut.androlib.Androlib.build ( androlib.java:176) at Brut.apktool.Main.cmdBuild (main.java:228) at Brut.apktool.Main.main (main.java:79) caused by: Brut.androlib.androlibexception:brut.cOmmon. Brutexception:could not EXEC command: [AAPT, P,--min-sdk-version, one,--target-sdk-version, A, F,/var/folders/7r/ghlh Nsm56fn9d3zwwmznrh9w0000gn/t/apktool4414016803544356394.tmp, 0, ARSC,-I,/users/shunpingliu/library/apktool/ framework/1.apk,-S,/users/shunpingliu/greensoftware/apktool/com.hiwifi.hiwifi_20140801181424/res,-M,/Users/ Shunpingliu/greensoftware/apktool/com.hiwifi.hiwifi_20140801181424/androidmanifest.xml]at Brut.androlib.res.AndrolibResources.aaptPackage (androlibresources.java:357) at Brut.androlib.Androlib.buildResourcesFull (androlib.java:336) ...  5 morecaused by:brut.common.BrutException:could not EXEC command: [AAPT, P,--min-sdk-version, one,--target-sdk-version, +-F,/var/folders/7r/ghlhnsm56fn9d3zwwmznrh9w0000gn/t/apktool4414016803544356394.tmp,-0, ARSC,-I,/Users/ shunpingliu/library/apktool/framework/1.apk,-S,/users/shunpingliu/greensoftware/apktool/com.hiwifi.hiwifi_ 20140801181424/res,-M,/users/shunpingliu/greensoftware/apktool/com.hiwifi.hiWifi_20140801181424/androidmanifest.xml]at brut.util.OS.exec (os.java:93) at Brut.androlib.res.AndrolibResources.aaptPackage (androlibresources.java:355) ... 6 morecaused By:java.io.IOException:Cannot Run Program "AAPT": error=2, No such file or Directoryat Java.lang.ProcessBui Lder.processexception (processbuilder.java:478) at Java.lang.ProcessBuilder.start (processbuilder.java:457) at Java.lang.Runtime.exec (runtime.java:593) at Java.lang.Runtime.exec (runtime.java:466) at Brut.util.OS.exec (Os.java : 84) ... 7 morecaused by:java.io.ioexception:error=2, No such file or Directoryat java.lang.UNIXProcess.forkAndExec (Native metho d) at java.lang.unixprocess.<init> (unixprocess.java:53) at Java.lang.ProcessImpl.start (processimpl.java:91) At Java.lang.ProcessBuilder.start (processbuilder.java:452) ... Ten more

Workaround:
Add the AAPT to the environment variable, this command is in the SDK.
The code on my machine is as follows: Vim ~/.bash_profile adds the following: (related to the respective file location)

Export path= "/users/shunpingliu/greensoftware/adt-bundle-mac-x86_64-20140321    /sdk/build-tools/android-4.4.2 : $PATH "

Then make the configuration effective
source. bash_profile
The full version of the script reference attachment.

1#!/bin/Bash2Apktool="/users/shunpingliu/greensoftware/apktool/apktool.jar"3#channellist ="Channel.data"4channellist="Channel.data"5ijiamifile="/volumes/macintoshhd/users/liushunping/station/apk/com.hiwifi.hiwifi_20140801181424_yingyongbao.apk" love the APK file after encryption"6Java-jar $apktool D-F $ijiamifile tobuild7     forChannelinch$(Cat$channellist)8     Do9        sed-I. Bak'145s/.*/<meta-data android:name= "Umeng_channel" android:value= "'${channel}'"\/>/'tobuild/Androidmanifest.xmlTenJava-jar $apktool B tobuild com.hiwifi.hiwifi_$channel.apk One     Done

Cygwin a simulated Linux environment for ant Bulk Packaging

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.