4

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:

  1. how to access resources in a android library project
  2. providing resource on android
  3. Accessing resources on android
Community
  • 1
  • 1
r0n9
  • 2,505
  • 1
  • 29
  • 43
  • I usually use a raw folder in the res folder, to store the images in the apk internal storage. But you need to add some functions in java to store your files. If I have time I will post an example. – uelordi Sep 29 '16 at 09:00

1 Answers1

7

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.

Community
  • 1
  • 1
  • Based on [this answer](http://stackoverflow.com/questions/6346889/how-to-reference-an-asset-in-a-library-project) a shared library is not able to access assets – r0n9 Sep 29 '16 at 04:08
  • The last edit of the referenced answer states that with the Gradle Build System, you should be able to access assets in a library. Did you try to use the AAssetManager? – Matthias Nefzger Sep 29 '16 at 04:12
  • Since I am not using the Android Studio, Gradle build system seems not a good option for me. – r0n9 Sep 29 '16 at 04:26