-
头文件不能少。
#include <android/asset_manager_jni.h>
#include <android/asset_manager.h> -
cmakelists.txt文件需要添加android这个lib,参考log-lib的套路。
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
find_library( # Sets the name of the path variable.
android-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
android)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
${android-lib}
# Links the target library to the log library
# included in the NDK.
${log-lib})
- Abort message: 'art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: jfieldID long android.content.res.AssetManager.mObject not valid for an object of xxxxxxx ... 如果遇到这个错误。
Java_com_example_liu_jnilearning_MainActivity_stringFromJNI(
JNIEnv *env,
void* reserved, // 加上这个
jobject assetManager,
jstring name,
jobject /* this */) {
//...
}