"Unable to get buffer of resource asset file"問題的解決

Problems 
When building you might run into the Unable to get buffer of resource asset file error. The root cause of this is that the new android resource file resources.arsc is larger than the aapt tool allows. You can exchange the .arsc file inside android.jar with an older version or patch the aapt tool by editing frameworks/base/include/utils/Asset.h.

Change both lines UNCOMPRESS_DATA_MAX = 1 * 1024 * 1024 to something bigger. As the new resources file currently has a size of 2.3Mb you should change the lines (both lines mind you) to at least 3*1024*1024.

 

在使用linux下面默認選項build出來的SDK作開發時候,出現了以下問題:

...Unable to get buffer of resource asset file


解決辦法是將build sdk時候的product該爲sdk,有兩種方法 :

1. 使用lunch更改配置:

cd ~/android/src
. build/envsetup.sh
lunch sdk-eng
make sdk

配置之後的結果是:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=1.6
TARGET_PRODUCT=sdk
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=Donut
============================================

2. 直接用make參數:

make PRODUCT-sdk-sdk

 


Asset限制文件大小UNCOMPRESS爲1MB 

  在使用Android自帶的Res/raw或使用Asset時都需要經過Asset Manager,這將會產生一個比較嚴重的問題,在Android模擬器測試時不存在問題,但放到真機G1時會面臨多個問題,經過查看 UNCOMPRESS_DATA_MAX的取值爲1048576字節,除以1024不難發現是1MB。也就是說Android手機在處理資源文件時不能大於1mb的體積。由於標準的G1沒有Root權限,無法訪問data/data/package name下面的文件夾,使用raw或asset存放的文件大小不能超過1048576字節,否則會在logcat下看到獲取到Debug類型的信息,tag爲asset(pid): Data exceeds UNCOMPRESS_DATA_MAX (2580997 vs 1048576) 可以看到接下產生了一個系統的錯誤,System.err,會發生java.io.IOException的異常。

  目前解決的方法只有將文件放入到sdcard,但這樣除了microsd的讀取IO效率和耗電量解決不是很好,同時sd卡移除時可能存在問題,解決的方法如果數據量大的化通過sqlite是一種解決方法,同時openFileOutput方式讀取也是不錯的選擇,看來android操作系統中最安全控制的嚴格,但犯了一個不小的錯誤。

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