未定义参考AAssetManager_fromJava [英] Undefined reference to AAssetManager_fromJava
问题描述
我试图使用AAssetManager一个Android APK访问的资产。不过,我不断收到
未定义的参考AAssetManager_fromJava即使我已经包括asset_manager.h和asset_manager_jni.h
从asset_manager.h其他功能,如AAssetManager_openDir(MGR,)等也不能被引用。
I am trying to access assets from an android apk using AAssetManager. However, I keep getting "Undefined reference to AAssetManager_fromJava" even though I've included asset_manager.h and asset_manager_jni.h Other functions from asset_manager.h, like AAssetManager_openDir(mgr, "") etc also can't be referenced.
下面是完整的code
Here's the complete code
#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
这code为.cpp文件,并正与NDK R8编译。我做得可怕的错误在这里?
This code is in a .cpp file and being compiled with NDK R8. Am I doing something terribly wrong here?
推荐答案
我的错。我没有Android的库添加到链接器。我对Visual Studio的前preSS实际安装NDK开发环境和Android的库未添加到默认情况下,我的项目。
My mistake. I didn't have "android" library added to the linker. I have actually setup NDK dev environment on Visual Studio Express and "android" library wasn't added to my project by default.
如果您正在使用的makefile,务必使用原生AssetManager时-landroid添加到您的LOCAL_LDLIBS。
If you are using makefiles, be sure to add -landroid to your LOCAL_LDLIBS when using native AssetManager.
这篇关于未定义参考AAssetManager_fromJava的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!