日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件

發布時間:2024/9/19 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題:

在做文本文件讀取時,從assert文件中獲取文件

getResources().getAssets().openFd("test.txt").getFileDescriptor()

會報錯,提示File not Found ,because the file compressed,查找了很多資料,android打包成apk時,在assert文件中,除了音視頻文件不壓縮外,像txt之類的會進行壓縮成zip包,以節約空間,所以getFileDescriptor()時獲取不到,

通用都是獲取文件流,但在做大文件讀取時,最新技術推薦使用java nio中內存映射技術MappedByteBuffer

public void openbook(FileDescriptor fileD) throws IOException {

//book_file = new File(strFilePath);

FileInputStream in=new FileInputStream(fileD);

long lLen = in.available();

m_mbBufLen = (int) lLen;

m_mbBuf =in.getChannel().map(

FileChannel.MapMode.READ_ONLY, 0, lLen);

}

問題參考:

When developing an Android app, any data file, image or XML file (that is, any Resource or Asset) you use is bundled into your application package (APK) for distribution. The Android Asset Packaging Tool, oraapt, is responsible for creating this bundle, which you can think of as a ZIP file with a particular layout that the Android OS can understand. When your application is installed, whether in development mode or by an end user, this APK file is simply dropped into a special location on the device’s (or emulator’s) filesystem.

As part of preparing your APK,aaptselectively compresses various assets to save space on the device. The wayaaptdetermines which assets need compression is by their file extension. The following code, taken fromPackage.cppin theaaptsource code, sheds some light on which types of files are not compressed by default:

/* these formats are already compressed, or don't compress well */

static const char* kNoCompressExt[] = {

".jpg", ".jpeg", ".png", ".gif",

".wav", ".mp2", ".mp3", ".ogg", ".aac",

".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet",

".rtttl", ".imy", ".xmf", ".mp4", ".m4a",

".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2",

".amr", ".awb", ".wma", ".wmv"

};

解決方案:

配置build.xml時配置不壓縮txt文件

D:\android-eclipse\sdk\tools\ant

command="package"

versioncode="${version.code}"

versionname="${version.name}"

debug="${build.is.packaging.debug}"

manifest="${out.manifest.abs.file}"

assets="${asset.absolute.dir}"

androidjar="${project.target.android.jar}"

apkfolder="${out.absolute.dir}"

nocrunch="${build.packaging.nocrunch}"

resourcefilename="${resource.package.file.name}"

resourcefilter="${aapt.resource.filter}"

libraryResFolderPathRefid="project.library.res.folder.path"

libraryPackagesRefid="project.library.packages"

libraryRFileRefid="project.library.bin.r.file.path"

previousBuildType="${build.last.target}"

buildType="${build.target}"

ignoreAssets="${aapt.ignore.assets}">

總結

以上是生活随笔為你收集整理的assert文件夹 设置android_android使用build.xml配置assert文件中不压缩的类型文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。