读取资源文件从Android原生环境我自己的APK自己的、环境、文件、资源

2023-09-03 21:51:13 作者:孤烟

我移植到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那么你就可以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.