CygWin模拟Linux环境进行Ant批量打包

运行环境:Windows7 + Cygwin + ant

第一种:有源码

这种方式比较 简单。利用ant打包。
直接shell脚本修改 配置渠道号的文件。
我们目前是用的umeng的。在AndroidManifest.xml里。
提供一个简单的修改渠道号的脚本。

配置:

1.环境变量配置:

  (1)cd~ 或 cd /home 进入用户目录

  其中.bash_profile文件为配置文件。

(2)输入cat .bash_profile查看该文件

  

其中配置了ndk路径,ant路径,sdk相关路径,也可以写成export PATH=/cygdrive/d/androidUitil/ADT/ADT/sdk/tools:{$PATH}样式,启动cygdrive在CygWin中代表磁盘。

2.项目文件配置【放置于项目根目录,与src目录同级】

(1)ant.properties 文件

# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
#  ‘source.dir‘ for the location of your java source folder and
#  ‘out.dir‘ for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
#  ‘key.store‘ for the location of your keystore and
#  ‘key.alias‘ for the name of the key to use.
# The password will be asked during the build when you use the ‘release‘ target.

key.store=【签名文件绝对路径】
key.store.password=【签名密码】
key.alias=【别名】
key.alias.password=【签名密码】

(2)local.properties文件

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=【sdk绝对路径】

(3)build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="【项目名称】" default="help">

    <!-- The local.properties file is created and updated by the ‘android‘ tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />

    <!-- The ant.properties file can be created by you. It is only edited by the
         ‘android‘ tool to add properties to it.
         This is the place to change some Ant specific build properties.
         Here are some properties you may 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 an integral part of the build system for your
         application and should be checked into Version Control Systems.

         -->
    <property file="ant.properties" />

    <!-- if sdk.dir was not set from one of the property file, then
         get it from the ANDROID_HOME env var.
         This must be 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 are stored in ant.properties
         (or in .classpath for Eclipse projects).

         This file is an integral part of the build system for your
         application and should be 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 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" />

    <!-- Import the actual build file.

         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *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 this file, replacing the <import> task.
             - customize to your needs.

         ***********************
         ****** IMPORTANT ******
         ***********************
         In all cases you must update the value of version-tag below to read ‘custom‘ instead of an integer,
         in order to avoid having your file be overridden by tools such as "android update project"
    -->
    <!-- version-tag: 1 -->
    <import file="${sdk.dir}/tools/ant/build.xml" />

</project>

3.渠道列表文件channel.data

4.编写shell脚本 apkList.sh文件

5.执行shell脚本

进入apkList.sh文件所在目录,执行./apkList.sh,即开始批量打包

第二种:无源码

由于我们用上了爱加密,所以也只能用这种方式了。
由于现在我们的渠道较少,所以是采纳了apktool 的方式。
第一步:反编译

java -jar apktool.jar d com.hiwifi.hiwifi_20140801181424.apk

第二步:修改渠道号

sed -i .bak ‘145s/.*/<meta-data android:name="UMENG_CHANNEL" android:value="‘${channel}‘" \/>/‘  tobuild/AndroidManifest.xml

第三步:重新编译

 java -jar apktool.jar b com.hiwifi.hiwifi_20140801181424 com.hiwifi.hiwifi_lenovo.apk

我在重新编译时遇到如下错误:

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, 11, --target-sdk-version, 19, -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.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, 11, --target-sdk-version, 19, -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.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:357)
	at brut.androlib.Androlib.buildResourcesFull(Androlib.java:336)
	... 5 more
Caused by: brut.common.BrutException: could not exec command: [aapt, p, --min-sdk-version, 11, --target-sdk-version, 19, -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 more
Caused by: java.io.IOException: Cannot run program "aapt": error=2, No such file or directory
	at java.lang.ProcessBuilder.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 more
Caused by: java.io.IOException: error=2, No such file or directory
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:53)
	at java.lang.ProcessImpl.start(ProcessImpl.java:91)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
	... 10 more

解决办法:
把aapt加到环境变量里去,这个命令在sdk中。
我机器上代码如下: vim ~/.bash_profile 增加以下内容:(和各自的文件位置有关)

export PATH="/Users/shunpingliu/GreenSoftware/adt-bundle-mac-x86_64-20140321    /sdk/build-tools/android-4.4.2:$PATH"

然后使配置生效
source .bash_profile
完整版脚本参考附件。

1    #!/bin/bash
2    apktool="/Users/shunpingliu/GreenSoftware/apktool/apktool.jar"
3    #channellist="channel.data"
4    channellist="channel.data"
5    ijiamifile="/Volumes/MacintoshHD/Users/liushunping/station/apk/com.hiwifi.hiwifi_20140801181424_yingyongbao.apk"    【爱加密之后的apk文件】
6    java -jar $apktool d -f $ijiamifile tobuild
7    for channel in $(cat $channellist)
8    do
9        sed -i .bak ‘145s/.*/<meta-data android:name="UMENG_CHANNEL" android:value="‘${channel}‘" \/>/‘  tobuild/AndroidManifest.xml
10        java -jar $apktool b tobuild com.hiwifi.hiwifi_$channel.apk
11    done
时间: 2024-10-08 06:06:31

CygWin模拟Linux环境进行Ant批量打包的相关文章

Windows下使用NCL(Cygwin模拟Linux环境)

参考自:http://bbs.lasg.ac.cn/bbs/thread-37043-1-1.html 1.下载 所需文件均可在此下载:http://yunpan.cn/cQsvAEe3Axs2Z  访问密码 2fa2 下载文件放到D:/anzhuang/目录下,cygwin.rar需解压,另一个ncl压缩文件不需要解压 2.安装Cygwin/X 1)点击cygwin文件夹下的setup.exe 2)点击“下一步”,出现“Choose Installation Type”,请选择“Install

cocos2dx Android 使用ant 批量打包

参考文章: 例子:http://www.2cto.com/kf/201305/208139.html http://blog.csdn.net/ljb_blog/article/details/12709983 eclipse 如何支持ant:http://www.cnblogs.com/sw926/p/3238512.html 环境介绍: 引擎:cocos2dx2.2.2 开发平台:mac jdk 1.7 注:参考了以上文章,最后发现打包也不用自己下ant,也不用命令行, 而是设置 <proj

使用Ant批量打包Android应用完全指南

本文章由Socks完成,博客地址:http://blog.csdn.net/zhaokaiqiang1992 转载请说明! 折腾了一下午,百度了一下午,终于实现了使用Ant对Android应用的批量打包,也算是了却了我的一桩心事.虽然网上的这部分教程也有,但是感觉写的不是详细.更为重要的是,各种方法之间的差异比较大,对于新手来说,各种方法之间的选择是极为痛苦的,一个方法一个方法的去实验,是很浪费时间的.因此,我想给大家提供一套完整的,详细的Ant打包Android应用的教程,方便大家的学习和以后

【Android开发经验】使用Ant批量打包Android应用全然指南

本文章由Socks完毕.博客地址:http://blog.csdn.net/zhaokaiqiang1992 转载请说明. 折腾了一下午.百度了一下午,最终实现了使用Ant对Android应用的批量打包,也算是了却了我的一桩心事.尽管网上的这部分教程也有,可是感觉写的不是具体. 更为重要的是.各种方法之间的差异比較大.对于新手来说.各种方法之间的选择是极为痛苦的,一个方法一个方法的去实验,是非常浪费时间的. 因此,我想给大家提供一套完整的,具体的Ant打包Android应用的教程,方便大家的学习

Android采用Ant批量打包

Ant批量打包的目的是:Android应用市场繁杂,有时候可能需要统计你的app在各个渠道的下载量等信息,而统计各个渠道时是要做区分的,你需要在项目的配置文件中添加数据元,来标示我们的应用是在哪个渠道上发布的. 1.准备工作: 在正式开始Ant打包前,需要下载和配置Ant环境,下载地址:ant下载 下载后解压安装包,解压后的目录如下: 接下来就是配置Ant的环境变量: 创建ANT_HOME变量,填入路径:E:\apache-ant-1.9.7-bin\apache-ant-1.9.7 然后在Pa

在windows下使用Cygwin模拟unix环境 并安装apt-cyg svn等插件

在windows下使用Cygwin模拟unix环境,并安装apt-cyg,svn等工具 一.Cygwin的安装 1. 下载Cygwin,这个可以到这里下载 ,至于使用32位的还是64位的版本可以根据自己的系统而定,打开下载好的setup-x86.exe(以64bitwindws系统为例) . 安装过程中注意勾选下面的包,为了后面的操作,我们有必要在这里选择一些必要的包进行安装: (1) curl:(2) git* (git,git-completion, git-gui, gitk):(3) l

androd Eclipse Ant 批量打包

androd Eclipse Ant 批量打包的相关网址  有全部的教程  如遇到打包的问题  可从以下的链接中查找答案  谢谢这些前辈分享的资源  在此引用表示感谢 http://blog.csdn.net/mxthing/article/details/45716671http://www.android100.org/html/201509/14/181502.html http://ant.apache.org/bindownload.cgi http://blog.csdn.net/z

mac下ant批量打包全过程

由于目前渠道很多,需要批量打包,一般是window下打包,但是mac下如何批量打包呢?其实挺麻烦的,具体步骤如下: 一.打包前准备工作 1.首先确定你的JDK版本为1.6! 2.在AndroidManifest.xml中application标签下添加一个用来识别渠道的标签: <meta-data  android:name="qudao"  android:value="channel" /> 3.为了让ant支持循环功能,我们要在Android SD

Android Ant批量打包

一.配置Ant环境变量 JAVA_HOME=/software/jdk1.6.0_24 ANT_HOME=/software/apache-ant-1.9.2 Android_Home=/software/android-sdk-linux export JAVA_HOME ANT_HOME Android_Home PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ANDROID_HOME/tools$Android_Home/tools/proguard/bin:$/so