我试图将安卓的versionName
在我的Android表现为存储在外部资源文件中的字符串资源的引用。
下面是摘自我的的AndroidManifest.xml
:
<清单 的xmlns:机器人=http://schemas.android.com/apk/res/android 包=com.toycorporation 安卓版code =@整数/ version_ code 机器人:=的versionName@字符串/ VERSION_NAME>
和位于下build.xml文件的内容 RES /值
disrectory我的项目:
<?XML版本=1.0编码=UTF-8&GT?;<资源的xmlns:机器人=http://schemas.android.com/apk/res/android> <项目类型=字符串NAME =build_date> 03 /二千零十二分之一十五< /项目> <项目类型=整数NAME =version_ code> 315281< /项目> <项目类型=字符串NAME =VERSION_NAME> 3.15.28.1< /项目>< /资源>
后来我尝试检索版本号来显示它我的应用程序的关于屏幕上。
PackageInfo packageInfo = getPackageManager()getPackageInfo(getPackageName(),0);Log.d(PackageInfo,版本名称:+将String.valueOf(packageInfo.versionName));
问题描述:
当我构建应用程序,并自动我的HTC设备上安装它一切都运行完美。版本名称被引用和关于屏幕上通过我得到记录在logcat的版本名称值。但是,当我试图构建应用程序并启动它在模拟器上我得到空
而不是版本名称值。
我已经尝试构建和安装应用程序使用Eclipse和IDEA到仿真器。这么看来这个问题是不相关的IDE。
更新:
一个额外的事情出现了,它不这样使用的versionName
的工作和版本code
。应用程序无法部署到谷歌播放。出现以下错误:
该文件是无效的:错误获取安卓版code'的属性: 属性是不是整数值
解决方案您可以在清单设置为的versionName字符串资源的引用,而不是版本code。
I'm trying to set the android:versionName
in my android manifest as a reference to string resource stored in external resource file.
Below is an excerpt from my AndroidManifest.xml
:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.toycorporation"
android:versionCode="@integer/version_code"
android:versionName="@string/version_name"
>
and the content of build.xml file located under res/values
disrectory of my project:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<item type="string" name="build_date">03/15/2012</item>
<item type="integer" name="version_code">315281</item>
<item type="string" name="version_name">3.15.28.1</item>
</resources>
Later I attempt to retrieve the version number to display it on the About screen of my application.
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),0);
Log.d("PackageInfo", "Version name: " + String.valueOf(packageInfo.versionName));
Problem description:
When I build the application and automatically install it on my HTC device everything works perfect. Version name gets passed by reference and on the About screen I get version name value logged in the logcat.
But when I attempt to build the application and launch it on the emulator I get null
instead of the version name value.
I have already tried to build and install the app to emulator using Eclipse and IDEA. So it seems the issue is not related to IDE.
UPDATE:
One additional thing appeared which doesn't work with such use of versionName
and versionCode
. Application can not be deployed to the Google Play. The following error appears:
The file is invalid: ERROR getting 'android:versionCode' attribute: attribute is not an integer value
解决方案
You can set versionName in manifest as a reference to string resource, but not versionCode.