引用 Android 清单版本代码的整数资源 [英] Reference an integer resource for Android manifest versionCode

查看:24
本文介绍了引用 Android 清单版本代码的整数资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用中:

In my Android app I:

  • 在构建过程中使用脚本生成递增的构建编号(整数)(使用来自 SVN 修订版的整数)
  • 我生成了一个定义为整数的 Android 资源文件:399

  • generate an incrementing build number (integer) using a script as part of my build (uses Integer from SVN revision)
  • I generate an Android resource file with it defined as an integer: 399

我使用上面生成的资源在 UI 上展示了这一点

I show that on the UI using the resource generated above

我在 Manifest 中为 versionCode 元素引用整数

I reference the integer in the Manifest for the versionCode element

一切正常,但是当我尝试上传到 Market 时出现此错误:

All that works fine, but when I attempt to upload to Market I get this error:

文件无效:获取'android:versionCode'属性时出错:属性不是整数值"

"The file is invalid: ERROR getting 'android:versionCode' attribute: attribute is not an integer value "

问题:对于 Market,versionCode 是否必须是直接在清单中的文字"整数,或者是否有某种方法可以引用外部生成的整数而不是一直(手动或自动)触摸我的清单.

Question: For Market, does the versionCode have to be a "literal" integer directly inside the manifest, or is there some way to reference an externally generated integer and not be touching my manifest all the time (manually or automatically).

谢谢(顺便说一句:我刚刚意识到该方案可能会导致我在补丁发布方面出现问题,所以我可能会生成更大的数字或其他东西,但仍然希望得到这个问题的答案)

thanks (BTW: I have just realized that scheme might cause me issues with patch releases, so I will probably generate a bigger number or something, but would still like the answer to this question)

推荐答案

最后我是这样做的:

我在我的版本控制系统中使用此格式的版本号创建了一个标签

I create a tag in my version control system with the numbe rof the release in this format

X.YY.ZZ 其中它们都是整数,例如 1.20.00,并保留最后两位数以用于计划外的补丁版本,可能会在发布更高版本后在分支上发布......

X.YY.ZZ where they are all integers, like 1.20.00, and reserve the last two digits for unplanned patch releases maybe made on a branch after a later release is made....

因此,如果我先发布 1.20.00 再发布 1.23.00,我仍然可以返回并发布一个名为 1.22.01 的 1.22.00 补丁.

So if I release 1.20.00 then 1.23.00, I can still go back and do a patch release to 1.22.00 called 1.22.01.

我有一个构建步骤,它获取标签名称并为我在 UI 中使用的 Android 生成字符串资源1.22.00".它还将它生成为数字 12200,我将其用作版本号.

I have a build step that gets the tag name and generates a string resource "1.22.00" for Android that I use in the UI. It also generates it as a number 12200 and I use this as the version number.

但是,我不会尝试将此版本号直接包含在清单中,我通过为版本代码设置 ant 属性来为包设置它,如果定义了该版本代码,则 ant 构建会拾取该属性并用于创建 .apk.

BUT, I don't try and include this version number directly in the manifest, I set it for the package by setting an ant property for version code that the ant build picks up if defined and uses to create the .apk.

所以我得到的 Android Market 整数总是递增的,但旧版本的用户可以安装补丁版本,但如果你有更新的官方版本,则无法安装补丁版本.

So I get an always increasing integer for Android Market, but a user with an older version can install a patch release, but you cannot install a patch release if you have a newer official release.

即如果您有 1.20.00,则可以安装补丁 1.20.01,但如果用户已移至 1.23.00,则他们无法安装 1.20.01 补丁...

i.e. if you have 1.20.00 you can install patch 1.20.01, but if a user has moved onto 1.23.00 they cannot install the 1.20.01 patch...

设置你可以使用的属性;project.setProperty("version.name", versionName);project.setProperty("version.code", versionCode);

To set the property you can use; project.setProperty("version.name", versionName); project.setProperty("version.code", versionCode);

如果设置了这些属性,那么 Android 构建系统(旧的和新的)将获取属性值并使用它,不需要做任何其他特殊的事情.

if those properties are set, then the Android build system (both old and newer) will pick-up the property value and use it, no need to do anything else special.

只需确保使用预构建/预编译 ant 扩展点之一进行设置.

Just make sure you set it using one of the pre-build/pre-compile ant extension points.

在 custom_rules.xml 的新构建系统(Platform Tools >= 12)中我添加了

In the new build system (Platform Tools >= 12) in custom_rules.xml I have added

<project name="custom" default="help">      
    <import file="build_info.xml" />
    <target name="-pre-build" depends="build-info" />
</project>

其中 build_info 是我自己的 ant 项目,它根据标签名称计算版本名称/编号(如果您在标签中构建......).

where build_info is my own ant project that calculates the version name/number from the Tag name (if you are building in a tag....).

这篇关于引用 Android 清单版本代码的整数资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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