简体   繁体   中英

Android, accessing resource files from a native/NDK shared library

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

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 (eg /storage or /sdcard) on the Java side and then only pass the filepath to the NDK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM