感谢以下文章:
http://chen592969029.iteye.com/blog/946056
实现功能:
在windows中的修改包名、自动替换渠道号、在原有的版本号中自动+1、使用当前时间做为版本号。
打包时自动更换友盟渠道
ant auto-release -DUMENG_CHANNEL=googlePlayStore
即会把AndroidManifest.xml中的友盟渠道替换成googlePlayStore,然后打包
ant auto-release -DUMENG_CHANNEL=xiaomiAppStore
即会打出小米应用商店的包
打包时自动更换包名
ant auto-release -Dpackage=com.example.ant.beta
把包名自动改成com.example.ant.beta,然后打包
打包时使用时间作为版本号
ant auto-debug -Dversion=time
把版本号改成时间,然后打包,效果:
versionCode是时间戳,比如1390969254
versionName是日期,比如14.1.29.1220
打包时版本自动+1
ant auto-debug -Dversion=addone
把版本号自动+1,然后打包,效果:
versionName原来是:1.4,则会变成1.5
多个参数任意组合
ant auto-release -DUMENG_CHANNEL=googlePlayStore -Dpackage=com.example.ant.beta -Dversion=time
即打出google play的beta包,使用时间作为版本号
如何集成到我的项目里
前提:了解Android官方文档,在项目目录中执行ant debug能打包,比如常见的打包步骤:
android update project -p . -s -t "android-19"
ant debug
custom_rules.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="auto-debug">
<property name="build.last.is.packaging.debug" value="true" />
<propertyfile file="auto.prop">
<entry key="build.last.is.packaging.debug" value="${build.last.is.packaging.debug}" />
</propertyfile>
<antcall target="-auto">
</antcall>
</target>
<target name="auto-release">
<antcall target="-auto">
</antcall>
</target>
<target name="-auto">
<!-- 复制项目到临时目录,避免替换打包影响本目录代码 -->
<dirname property="auto.here.dir" file="${ant.file}" />
<property name="auto.project.tmp.dir" value="${auto.here.dir}Tmp" />
<delete dir="${auto.project.tmp.dir}" />
<copy todir="${auto.project.tmp.dir}" overwrite="true">
<fileset dir="./">
<!-- 忽略隐藏文件 -->
<exclude name=".*" />
<exclude name=".*/*" />
</fileset>
</copy>
<!-- 解析AndroidManifest.xml 获得包名 -->
<xmlproperty file="AndroidManifest.xml" collapseAttributes="true" />
<!-- 写入配置文件 -->
<propertyfile file="auto.prop">
<entry key="auto.package" value="${manifest.package}" />
<entry key="auto.final.versionCode" value="${manifest.android:versionCode}" />
<entry key="auto.final.versionName" value="${manifest.android:versionName}" />
<entry key="auto.project.tmp.dir" value="${auto.project.tmp.dir}" />
</propertyfile>
<!-- 检查参数或配置中是否指定了包名 -->
<condition property="auto.has.package">
<isset property="package" />
</condition>
<!-- 修改包名 -->
<antcall target="-change-package-name">
</antcall>
<!-- 修改友盟渠道 -->
<antcall target="-change-umeng-channel">
</antcall>
<condition property="auto.version.is.time">
<equals arg1="${version}" arg2="time" />
</condition>
<condition property="auto.version.is.addone">
<equals arg1="${version}" arg2="addone" />
</condition>
<!-- 修改版本号 -->
<antcall target="-change-version-time">
</antcall>
<antcall target="-change-version-addone">
</antcall>
<condition property="build.last.target" value="debug" else="release">
<istrue value="${build.last.is.packaging.debug}" />
</condition>
<!-- 执行ant debug或者ant release进行打包 -->
<exec dir="${auto.project.tmp.dir}" executable="ant.bat">
<arg value="${build.last.target}" />
</exec>
<!-- 复制打好的包 到 本目录下 -->
<antcall target="-cp-out-final-file">
</antcall>
<property file="auto.prop" />
<echo message="package: ${auto.package}" />
<echo message="UMENG_CHANNEL : ${auto.umeng.channel}" />
<echo message="versionCode: ${auto.final.versionCode}" />
<echo message="versionName: ${auto.final.versionName}" />
</target>
<target name="-change-package-name" if="auto.has.package">
<propertyfile file="auto.prop">
<entry key="auto.package" value="${package}" />
</propertyfile>
<echo message="old package: ${manifest.package}" />
<echo message="new package: ${package}" />
<replace dir="${auto.project.tmp.dir}" excludes="build.xml" token="${manifest.package}" value="${package}">
</replace>
</target>
<target name="-change-umeng-channel">
<condition property="UMENG_CHANNEL" value="debug" else="release">
<istrue value="${build.last.is.packaging.debug}" />
</condition>
<propertyfile file="auto.prop">
<entry key="auto.umeng.channel" value="${UMENG_CHANNEL}" />
</propertyfile>
<echo message="UMENG_CHANNEL : ${UMENG_CHANNEL}" />
<replaceregexp encoding="utf-8" file="${auto.project.tmp.dir}/AndroidManifest.xml"
match="<meta\-data(\s+)android:name="UMENG_CHANNEL"(\s+)android:value="[a-zA-Z0-9]+""
replace="<meta\-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL}""
/>
</target>
<!-- 使用时间戳作为版本数字,使用日期作为版本名,比如Ubuntu 13.04使用yy.MM,MIUI 4.1.17使用年的最后一位.M.d
本脚本使用 yy.M.d.HHmm,比如14.1.1.1800 表示 14年1月1日18点00分。
由于开发时经常发布版本,所以精确到分钟。可能几分钟前刚打的包,改了字符串,又重新打包。
-->
<target name="-change-version-time" if="auto.version.is.time">
<script language="javascript">
<![CDATA[
property = project.setProperty("now",Math.floor((new Date()).getTime()/1000));
]]>
</script>
<tstamp>
<format property="auto.final.versionCode"
pattern="${now}" />
<format property="auto.final.versionName"
pattern="yy.M.d.HHmm" />
</tstamp>
<propertyfile file="auto.prop">
<entry key="auto.final.versionCode" value="${auto.final.versionCode}" />
<entry key="auto.final.versionName" value="${auto.final.versionName}" />
</propertyfile>
<echo message="versionCode: ${auto.final.versionCode}" />
<echo message="versionName: ${auto.final.versionName}" />
<replaceregexp file="${auto.project.tmp.dir}/AndroidManifest.xml"
match="android:versionCode="(\d+)""
replace="android:versionCode="${auto.final.versionCode}""
/>
<replaceregexp file="${auto.project.tmp.dir}/AndroidManifest.xml"
match="android:versionName="([a-zA-Z0-9\.]+)""
replace="android:versionName="${auto.final.versionName}""
/>
</target>
<!--使android:versionName版本自动加1 -->
<target name="-change-version-addone" if="auto.version.is.addone">
<echo>-----------------------------------------版本修改前:${manifest.android:versionName}</echo>
<script language="javascript">
<![CDATA[
str=project.getProperty("manifest.android:versionName");
var strs= new Array();
str=str.replace(".",",");
strs=str.split(",");
version="";
for (i=0; i < strs.length-1; i++ ) {
version += strs[i] +".";
}
if (strs.length > 2){
version += (parseInt(strs[strs.length-1])+1);
}else{
version += strs[strs.length-1] + ".0.1";
}
if (strs.length>=2)
{
bigVersion = strs[0]+ "." + strs[1];
}
property = project.setProperty("auto.final.versionNam",version);
property = project.setProperty("bigVersion",bigVersion);
]]>
</script>
<echo>-----------------------------------------版本修改后:${auto.final.versionName}</echo>
<propertyfile file="auto.prop">
<entry key="auto.final.versionName" value="${auto.final.versionName}" />
</propertyfile>
<replaceregexp file="${auto.project.tmp.dir}/AndroidManifest.xml"
match="android:versionName="([a-zA-Z0-9\.]+)""
replace="android:versionName="${auto.final.versionName}""
/>
<replaceregexp file="AndroidManifest.xml"
match="android:versionName="([a-zA-Z0-9\.]+)""
replace="android:versionName="${auto.final.versionName}""
/>
</target>
<target name="-cp-out-final-file">
<property file="auto.prop" />
<condition property="build.last.target" value="debug" else="release">
<istrue value="${build.last.is.packaging.debug}" />
</condition>
<copy file="${auto.project.tmp.dir}/${out.dir}/${ant.project.name}-${build.last.target}.apk" tofile="${out.absolute.dir}/${auto.package}-${auto.final.versionName}-${auto.umeng.channel}-${build.last.target}.apk" overwrite="true">
</copy>
</target>
</project>
版权声明:本文为博主原创文章,未经博主允许不得转载。
分享到:
相关推荐
1.请求服务器获取服务器存储的版本信息 2.通过比对手机端的版本和服务器的版本 3如果要更新需要符合以下判断条件 1)sdcard是否存在 2)sdcard剩余存储量与apk文件大小的比对 3)是否在wifi环境下 4.下载...
Java解析apk/ipa读取包名、版本名、版本号等等信息源码,自己总结,希望对大家有所帮助。
一. 打开项目选择如图示1 (build.gradle 项目... 自动追加版本号和版本名称 android.applicationVariants.all { variant->variant.outputs.each { output-> output.outputFile = new File(output.outputFile.paren
自己写了一个解析APK的工具,主要可以解析到APK包的版本名称,版本号,包名,ICON图片。有两个版本,分别支持32位系统和64位系统,前提是系统要有java环境。同时支持单个APK解析和多个APK解析。多个只需要指定文件夹...
利用shell脚本加python在Mac环境下实现解压apk,读取AndroidManifest.xml中的渠道号并显示在终端里,用于检测apk自动编译的渠道包名称是否正确
这个免费的小工具还不到1MB,简单却颇为实用,可以显示APK对应的应用名、图标、版本、封装...它甚至能帮你将APK自动改成简单的名字(软件名_版本号),这在备份大量应用的时候非常有用。 虽然是英文的,使用起来也很简单
4、创建密钥库及密钥,创建后会自动选择刚创建的密钥库和密钥, 点击“Create new…”按钮创建密钥库 (已拥有密钥库跳过这一步) 5、一下内容一般都是自己带出来的,是否记住密码可选可不选 接下来就是Next 6、 7...
-versionCode 版本号 -versionName 版本名称,如1.0.3 -packageName Apk包名 -certs [index] [MD5|SHA1|issuer|subject|validity] 获取证书的信息 -verify 校验apk内文件的签名,并列出未通过校验的文件 -...
1. 支持安卓、苹果APP包上传后自动解析读取包信息,减少用户手动录入的繁琐。 2. 支持苹果APP开发包上传后,自动打包企业认证,提供在线安装IPA包功能。方便公司内部各种历史版本上传就可以安装,减少手工打包的...
Jenkins:Jenkins + gradle + svn + windows自动化编译,上传svn; apk注入svn源码路径,版本号,jenkins build号
2.从服务器获取版本号(版本号存在于xml文件中)并与当前检测到的版本进行匹配,如果不匹配,提示用户进行升级,如果匹配则进入程序主界面。 3.当提示用户进行版本升级时,如果用户点击了确定,系统将自动从服务器...
1.获取线上App版本号和当前App版本号 2.比对版本号,判断是否资源在线升级更新 3.是否下载最新安装包[可以静默下载或用户触发] 4.是否执行资源在线升级更新[可以主动或用户触发] 5.是否立即重启生效[可以主动或用户...
自动呼叫记录器专业版APK 记录所有的电话 呼叫 ,你想,然后选择你要保存的要求。您可以设置记录哪些呼叫以及忽略哪些呼叫。收听录音,添加备注并分享。与Google Drive™和Dropbox集成,可以保存呼叫并同步到云端。...
Android渠道打包工具Gradle插件 渠道包数量很多(如100个以上),对打包速度有要求的建议使用新版极速打包工具 Packer-Ng,100个渠道包只需...支持自动修改versionName中的build版本号,实现版本号自动增长 gradle-pa
在程序启动的时候首先调用更新模块检测服务器上存放的版本号跟当前程序的版本号如果大于当前版本号,弹出更新对话框,如果用户选择更新,则显示当前更新状态,然后替换当前程序。 程序调用版本更新检测: private ...
此程序在其基础上完善并添加一些功能,此版本号定位2.0 最终版。 定为最终版的原因是支持动态加载最新的内置工具: ..\Bin\*.*目录下的所有工具如果有最新版本的,替换Bin目录内的程序即可应用最新版。 [注意:不要...
Log.d("star","当前版本号小于2进行增量更新${BuildConfig.VERSION_CODE}") doBspatchTask() }else{ Log.d("star","当前最新版本不需更新") Log.d("star","当前版本号小于2进行增量更新${BuildConfig.VERSION_...
.setNewVersion("1.0.1")//设置即将下载的APK的版本号,避免重复下载 .setFileSavePath(savePath)//设置文件保存路径(可不设置) .setNotificationIconRes(R.mipmap.app_icon)//设置通知图标 ....
zetaTorrent Pro - Torrent应用程序 ZetaTorrent是一个内置浏览器,允许打开和下载torrent文件的内容。 专业特色: 内置浏览器 ...版本号太高(下一个版本后不会要求更新) 宣言已经清理完毕 优化