Kalen
Kalen

Reputation: 3126

Reading Resource Files from my own APK in Android Native Environment

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.

Upvotes: 15

Views: 13983

Answers (2)

Justin Buser
Justin Buser

Reputation: 2871

Check out obb.h in the ndk.

From docs/STABLE-APIS.html in the Android NDK:

<android/obb.h>
        Direct (read-only) access to assets embedded in your .apk. or
        the Opaque Binary Blob (OBB) files, a new feature of Android X.X
        that allows one to distribute large amount of application data
        outside of the .apk (useful for game assets, for example).

Upvotes: 5

Tim Kryger
Tim Kryger

Reputation: 11246

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.

Upvotes: 15

Related Questions