Reputation: 2729
I am working on creating a native shared library for an older android API level. I am able to invoke functions in the library from client code.
But I need to use some image files in the shared library. The reference 1 && 3 mentioned a way to access resource files by using java code. My question is: is there a way allowing me to use (something like fopen(res_path)) c/c++ function to open resource files?
The library source structure is:
.
├── AndroidManifest.xml
├── Android.mk
├── Application.mk
├── res
│ └── drawable
│ ├── 0.jpg
│ ├── 1.jpg
│ ├── ...
│ └── 9.jpg
├── MyApp.cpp
└── MyApp.h
Thanks in advance
environment:
ndk ver : ndk-r12b
compiler: gcc c/c++ 4.9.x
AOSP : 5.1.1_r30
API level: 22
references:
Upvotes: 5
Views: 9942
Reputation: 114
According to this answer, the NDK provides an API to access the assets folder (AAssetManager
, see here).
Alternatively, an easy way that I used in one of my projects is to write the necessary files to the filesystem (e.g. /storage or /sdcard) on the Java side and then only pass the filepath to the NDK.
Upvotes: 8