使用ant构建Android apk时如何在文件名中包含版本字符串? [英] How to include version string in the filename when building Android apk with ant?

查看:23
本文介绍了使用ant构建Android apk时如何在文件名中包含版本字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我们在调试模式下使用命令构建android包

Normally we build android package in debug mode with the command

ant debug

并获得 apk 文件名 AppName-debug.apk.

and got the apk filename AppName-debug.apk.

有没有办法直接生成AppName-debug-.apk格式的apk文件,不用'mv'命令?

Is there any way to generate the apk file in the format of AppName-debug-<version-number>.apk directly without 'mv' command?

谢谢.

推荐答案

我已经通过使用 Android 清单中的信息以自动方式完成了这项工作.

I have done this in an automated way, by using the info from the Android manifest.

我的方法是修改本地项目antbuild.xml文件,在最新版本的SDK中导入主build.xml文件的自定义副本导入到本地文件的主文件位于 <SDK>/tools/ant/build.xml(在以前的版本中是 android_rules.xml) 注意 import 项目本地的默认 build.xml 文件中的行.

My approach was to modify the local project ant build.xml file to import a custom copy of the master build.xml file, in the latest version of the SDK the master file that is imported into your local file is located at <SDK>/tools/ant/build.xml (was android_rules.xml in previous versions) Note the import line in the default build.xml file local to your project.

Android 工具创建的本地 build.xml 中的注释包含有关如何进行自定义的详细信息,以便将来对工具的更新不会破坏您的更改.

The comments in the local build.xml created by the Android tools contain details on how to do customization, such that future updates to the tools will not break your changes.

在自定义规则文件中添加:

In the custom rules file add:

<xmlproperty file="AndroidManifest.xml" prefix="mymanifest" collapseAttributes="true"/>

这会将清单作为一组 ant 属性读取,并带有自定义前缀以确保不会发生名称冲突.

This reads in the manifest as a set of ant properties, with a custom prefix to ensure no name collision.

然后您可以将 ${mymanifest.manifest.android:versionName} 添加到定义了 apk 名称的任何位置,只需在其中搜索 .apk自定义规则文件.

You can then add ${mymanifest.manifest.android:versionName} to any of the spots that the apk name is defined, just search for .apk in the custom rules file.

我已经使用这个过程从构建服务器自动化版本控制文件.

I've used this process to automate versioning files from a build server.

通过一些额外的调整,还可以让您的发布应用程序自动签名,购买在属性中设置密码并在签名任务中使用密码.实际密码存储在单独的属性文件中,该文件仅存在于构建服务器上.虽然安全风险很小,但在某些情况下,完全端到端构建自动化的需求会抵消它.

With some additional tweaks it is also possible to have your release app signed automatically, buy setting the passwords in properties and using those in the signing task. The actual passwords where stored in a separate properties file that only lived on the build server. While a minor security risk, in some cases it is out weighed by the need for full end to end build automation.

这篇关于使用ant构建Android apk时如何在文件名中包含版本字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆