引用一个整数的资源用于Android清单版本code整数、清单、版本、资源

2023-09-06 04:01:02 作者:精神病院Ⅴiρ客户

在我的Andr​​oid应用我:

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

我表明,使用上述

我引用清单中的整数版本code元  

I reference the integer in the Manifest for the versionCode element

所有这一切工作正常,但是当我试图上传到市场我得到这个错误:

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

的文件是无效:错误获取安卓版code'的属性:属性是不是整数值

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

问: 对于市场,请问版code都直接是体现在一个文字的整数,或者是有一些方法来引用外部生成的整数,而不是被摸我的清单所有的时间(手动或自动)。

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)

推荐答案

在最后,这是我做了什么:

In the end, this is what I have done:

我创造我的版本控制系统与numbe ROF释放标签的格式

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

X.YY.ZZ,他们都是整数,像零零年一月二十零日,并保留最后两位数字进行计划外的补丁版本可能作出以后的版本中作出后的一个分支....

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....

所以,如果我释放零零年一月二十〇日那么00年1月23日,我还可以回去做一个补丁发布于00年1月22日被称为01年1月22日。

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.

我有一个生成步骤,获取标记名称,并生成一个字符串资源00年1月22日为Android,我在UI使用。它还生成它作为一个数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.

但是,我不要试图直接包含在清单中这个版本号,我通过设置一只蚂蚁属性的版本code。该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电子市场始终递增的整数,但与旧版本的用户可以安装一个补丁发布,但如果你有一个新的正式发布则无法安装补丁发布。

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.

即。如果你有零零年一月二十○日你可以安装补丁01年1月20号,但是如果用户已经转移到00年1月23日,他们无法安装补丁01年1月20号...

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(版本code,版本code);

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.

只要确保你设置使用pre-构建/ pre-编译蚂蚁扩展点之一吧。

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

在新的编译系统(平台工具> = 12)custom_rules.xml我已经加入

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....).