2012-09-23 17 views
8

Estoy intentando acceder a los recursos desde una apk de Android utilizando AAssetManager. Sin embargo, sigo obteniendo "Referencia indefinida a AAssetManager_fromJava" aunque he incluido asset_manager.h y asset_manager_jni.h No se pueden hacer referencia a otras funciones de asset_manager.h, como AAssetManager_openDir (mgr, "") etc.Referencia no definida a AAssetManager_fromJava

Aquí está el código completo

#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 

Este código está en un archivo .cpp y ser compilado con NDK R8. ¿Estoy haciendo algo terriblemente mal aquí?

Respuesta

14

Mi error. No tenía la biblioteca "Android" agregada al enlazador. De hecho, he configurado el entorno de desarrollo NDK en Visual Studio Express y la biblioteca "Android" no se agregó a mi proyecto de forma predeterminada.

Si está utilizando makefiles, asegúrese de agregar -landroid a su LOCAL_LDLIBS cuando use AssetManager nativo.

+0

Tengo el mismo problema aunque agregué -landroid a tu LOCAL_LDLIBS a mi archivo Android.mk – Ege

+0

@Ege tengo claro tu problema .. –

+0

#LifeSaver Muchas gracias por esto – FrickeFresh

1

me fijo mediante la adición siguiente para Android.mk

LOCAL_SHARED_LIBRARIES += libandroid 
2

que añade lo siguiente al gradle.build

android.ndk { ldLibs.addAll(["android", "log"]) }

1

desarrolladores de Android Studio Si usted tiene ExternalNativeBuild archivo que se llama " CMakeList.txt "debe agregar este código a 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}) 

si también tiene nativa lib puede agregar facilmente como esto

target_link_libraries(native-lib 
        ${log-lib} 
        ${android-lib}) 

Eso es lo que funciona greatfully!

Cuestiones relacionadas