我正在尝试使用 AAssetManager 从 Android apk 访问资源。然而,我不断得到
“未定义对 AAssetManager_fromJava 的引用”,即使我已包含 asset_manager.h 和 asset_manager_jni.h
asset_manager.h 中的其他函数,如 AAssetManager_openDir(mgr, "") 等也无法引用。
这是完整的代码
#define EXPORT_API
#include <string.h>
#include <jni.h>
#include <android\log.h>
#include <sys\types.h>
#include <android\asset_manager.h>
#include <android\asset_manager_jni.h>
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "com.devin - native", __VA_ARGS__)
JNIEnv* env=0;
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* pvt){
LOGD("JNI_OnLoad() called");
vm->AttachCurrentThread(&env, 0);
return JNI_VERSION_1_2;
}
EXPORT_API void LoadAsset(char* filename, jobject assetManager){
AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
/* More stuff */
}
#ifdef __cplusplus
};
#endif
此代码位于 .cpp 文件中,并使用 NDK R8 进行编译。我在这里做错了什么吗?
Android Studio 开发人员,如果您有名为“CMakeList.txt”的ExternalNativeBuild 文件,则必须将此代码附加到文件 CMakeList.txt
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 )
target_link_libraries(
${log-lib}
${android-lib})
如果您也有本机库,您可以像这样轻松添加
target_link_libraries( native-lib
${log-lib}
${android-lib})
它应该有效!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)