码迷,mamicode.com
首页 > 其他好文 > 详细

Ant多渠道打包

时间:2015-12-25 19:15:17      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

1.下载并安装ant。
到官方主页http://ant.apache.org下载新版(目前为Ant1.8.1)的ant,得到的是一个apache-ant-1.8.1-bin.zip的压缩包。将其解压到你的硬盘上,例如:D:\apache-ant-1.8.1。

http://ant-contrib.sourceforge.net/ 循环打包核心包,解压缩中打开,修改.properties文件,注释里面的if语句,前面加个#号即可

    完成后,复制到ant解压后的目录lib目录
2.配置环境变量。
依次选择:我的电脑->属性->高级->环境变量->系统变量->Path->编辑->变量值,在最前面添加如下内容:
D:\apache-ant-1.8.1\bin;
然后点击“确定”,完成环境变量的配置。
3.验证ant。
为了验证ant是否成功安装,可以进行如下操作:
依次选择:开始->运行->cmd,输入如下命令:
ant
如果出现如下内容,说明安装成功:
Buildfile: build.xml does not exist!
Build failed
但如果出现如下内容,说明安装失败:(应重复前述步骤,直至安装成功。)
‘ant‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。

==================================================================

核心参考代码如下:

注意,

<meta-data android:name="UMENG_CHANNEL" android:value="360" />

必须是一行,

<meta-data android:name="UMENG_CHANNEL"

android:value="360" />//错误格式

参考代码:

//运行命令,生成build.xml等文件

// 一切建立在配置了环境变量

==========

    切换到项目目录:

      android update project --name 你的项目名称 -t 1 --path .

      -t 为目标平台的版本编号 ,cmd下运行  android list target  即可获得

    =============

// build.xml,可以直接复制使用,只需修改一部分即可

<?xml version="1.0" encoding="UTF-8"?>
<!-- 项目名称MyJoke,可用全局替换为当前项目名称 为什么会有\x3Cdir\x3E这个东西,其实就是<dir>,不过ant build.xml中不允许使用‘<‘字符,所以要转义一下-->
<project name="MyJoke" default="deploy">


<property file="local.properties" />

 

<property file="ant.properties" />

 

<loadproperties srcFile="project.properties" />

<property name="aapt.ignore.assets" value="!.svn:!.git:\x3Cdir\x3E_*:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:crunch" />
<fail message="sdk.dir is missing. Make sure to generate local.properties using ‘android update project‘ or to inject it through an env var" unless="sdk.dir" />

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<!-- 自己本机路径为准 -->
<pathelement location="D:/JULY/ant/lib/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>

<import file="${sdk.dir}/tools/ant/build.xml" />

<target name="deploy">

<foreach delimiter="," list="${market_channels}" param="channel" target="modify_manifest">
</foreach>
</target>

<target name="modify_manifest">

<replaceregexp flags="g" byline="false" encoding="utf-8">
<regexp pattern="android:name=&quot;UMENG_CHANNEL&quot; android:value=&quot;(.*)&quot;" />
<substitution expression="android:name=&quot;UMENG_CHANNEL&quot; android:value=&quot;${channel}&quot;" />
<fileset dir="" includes="AndroidManifest.xml" />
</replaceregexp>
<antcall target="release" />
<echo message="========BEGIN================" />
<copy tofile="${gos.path}/${ant.project.name}_${channel}.apk">

<fileset dir="${out.absolute.dir}/" includes="${ant.project.name}-release.apk" />
</copy>
<!-- 删除临时的目录 -->
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*.d" />
</delete>
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*.prop" />
</delete>
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*.txt" />
</delete>
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*.ap_" />
</delete>
<delete includeEmptyDirs="true">
<fileset dir="${out.absolute.dir}" includes="**/*.dex" />
</delete>
<deltree dir="${out.absolute.dir}/proguard" />

<echo message="========SUCCESSFULLY================" />
<echo message="========SUCCESSFULLY================================" />
<echo message="========SUCCESSFULLY================" />
</target>

</project>

 

ant.properties

========================================================================

#app_version=1.0.4 \uFF08\u8981\u6253\u7684\u6E20\u9053\u5305\u7684\u7248\u672C\u540D\u79F0\uFF09
#market_channels=guanwang,shuihu,wushen,shenhua,huawei \uFF08\u6E20\u9053\u540D\u79F0\uFF0C\u8981\u4EE5\u9017\u53F7\u5206\u9694\uFF0C\u5FC5\u987B\u5728\u4E00\u884C\u5185\uFF09
application.package=com.mmeng.xx
ant.project.name=MyJoke
java.encoding=utf-8
#tem directory
out.absolute.dir=D:/Out/temp1
#apk directory/goal directory
gos.path=D:/Out/JULY_2015_12_251
key.store=C:/Users/1/Desktop/majun00.keystore
key.store.password=majunjun1
key.alias=m1
key.alias.password=1111111
app_version=1.0
market_channels=360
#market_channels=360,jifeng,gstone_dev,gstone,baidu,91,anzhuo,huawei,xiaomi,yingyongbao,wandoujia,anzhi,yingyonghui
#market_channels=jifeng
#market_channels=yingyongbao

    

 

Ant多渠道打包

标签:

原文地址:http://www.cnblogs.com/july2015/p/5076659.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!