Android錯誤引用自定義資源數據類型,造成安裝解析產生未知錯誤

Android 2.3.3           
Eclipse Version: 3.7.0           
LogCat Console 
 

報錯信息:

[2012-02-15 10:24:31 - taobao] ------------------------------
[2012-02-15 10:24:31 - taobao] Android Launch!
[2012-02-15 10:24:31 - taobao] adb is running normally.
[2012-02-15 10:24:31 - taobao] Performing com.taobao.htc.Start activity launch
[2012-02-15 10:24:31 - taobao] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'htc'
[2012-02-15 10:24:31 - taobao] Uploading taobao.apk onto device 'emulator-5554'
[2012-02-15 10:24:36 - taobao] Installing taobao.apk...
[2012-02-15 10:24:39 - taobao] Installation error: INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
[2012-02-15 10:24:39 - taobao] Please check logcat output for more details.
[2012-02-15 10:24:39 - taobao] Launch canceled!


發生錯誤原因分析:

安裝解析失敗,遇到未知錯誤。

 

分析AndroidManifest.xml,android:versionCode引用自定義資源

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="com.taobao.htc" android:versionCode="@string/app_versionCode" android:versionName="@string/app_versionName">


在strings.xml中也有app_versionCode對應值

Xml代碼  

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<string name="app_versionCode">360</string>

兩部分配置在Eclipse中均未提示錯誤。

 

根據在AndroidManifest.xml中直接配置versionCode值的經驗,其值應爲整數,否則Eclipse報錯。

error: Error: String types not allowed (at 'versionCode' with value 'htc').
error: Error: Float types not allowed (at 'versionCode' with value '360.0').  
error: Error: Boolean types not allowed (at 'versionCode' with value 'true'). 


解決辦法:

修改xml配置

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	package="com.taobao.htc" android:versionCode="@integer/app_versionCode" android:versionName="@string/app_versionName">
 
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<integer name="app_versionCode">360</integer> 

重新運行,正常。

 

不管是直接配置,還是使用引用資源,android:versionCode的值都只能是整數。

引用資源,一定要使用可用的數據類型。

 

PS:Eclipse的Problems並不是所有錯誤都能給出提示。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章