先决条件:
- apache ant
-
antcontrib
具体步骤:
- 在?AndroidManifest.xml 中添加meta-data 标签:
<meta-data android:name="UMENG_CHANNEL" android:value="10086" ></meta-data>
- 生成ant build.xml
android update project?-p?[project_path] - 在ant.properties文件中添加如下配置
application.package=com.sage.jiecai ant.project.name=jiecaijava.encoding=utf-8proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txtkey.store=sign/android.keystorekey.store.password=storepasswordkey.alias=jiecaikey.alias.password=aliaspasswordversion=1.0market_channels=51jiecai,360,qq,hiapk,baidu,91,wandoujia,xiaomi,10086
- 在build.xml中添加如下代码
<property file="ant.properties"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"> <classpath> <pathelement location="/Library/ant/lib/ant-contrib-1.0b3.jar"/> </classpath></taskdef> <import file="${sdk.dir}/tools/ant/build.xml"/><target name="deploy"> <foreach target="modify_manifest" list="${market_channels}" param="channel" delimiter=","> </foreach></target> <target name="modify_manifest"> <echo message="===========================${channel}========================="/> <replaceregexp flags="g" byline="false">?<!-- 匹配的内容是 android:value="*****" android:name="UMENG_CHANNEL" -->?<regexp pattern=‘android:name="UMENG_CHANNEL" android:value="(.*)"‘/>?<!-- 匹配之后将其替换为 android:value="渠道名" android:name="UMENG_CHANNEL" -->?<substitution expression=‘android:name="UMENG_CHANNEL" android:value="${channel}"‘/>?<!-- 正则表达式需要匹配的文件为AndroidManifest.xml -->?<fileset dir="" includes="AndroidManifest.xml"/> </replaceregexp> <echo message="===========================${channel}========================="/> <property name="out.release.file" location="${out.absolute.dir}/${ant.project.name}_${channel}.apk"/>?<!--包 -->?<antcall target="release"/>?<!--输出渠道包到bin/out目录下 -->?<copy tofile="${out.absolute.dir}/out/${ant.project.name}_v${version}-${channel}.apk"?file="bin/${ant.project.name}-release.apk"/> <echo message="===========================end============================="/></target>
?
时间: 2024-10-03 05:28:25