本文介绍了读取资源文件从Android原生环境我自己的APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植到Android。我现有的项目有一吨是我移植到我的Andr​​oid项目的资源文件。我把它们都在/ RES /生/,我想访问这些资源在我的本地库函数,如fopen()和等。可以这样做,还是我必须去通过JNI这个呢?我真的preFER不,为便于移植和可能的速度和内存的原因。

I'm porting to Android. My existing project has a ton of resource files that I'm porting into my Android project. I have them all in /res/raw/, and I would like to access those resources in my native library with functions such as fopen() and such. Can this be done, or do I have to go through JNI for this as well? I would really prefer not to, for ease of porting and possible speed and memory reasons.

推荐答案

如果您 $ P $因为它们添加到您的APK那么你就可以 pvent您的资产href="http://groups.google.com/group/android-ndk/browse_thread/thread/a69084018e87a5a8/9c513f8eb2956b87">use openRawResourceFd()来获得一个文件描述符,偏移和大小并传递给你的本地code,你只是做一个的fopen和fseek的。在另一方面,如果你让构建系统融为一体preSS要访问这些文件,你需要使用像 libzip 从APK阅读。

If you prevent your assets from being compressed as they are added into your APK then you can use openRawResourceFd() to get a file descriptor, offset, and size and pass them to your native code where you just do an fopen and fseek. On the other hand, if you let the build system compress the files you want to access, you will need to use something like libzip to read them from the APK.

这篇关于读取资源文件从Android原生环境我自己的APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多