Android ndk (cmake): 'referencia indefinida a `__android_log_write' cuando se usa log api en la segunda biblioteca jni

Uso Android Studio 2.2 y cmake para construir el archivo jni.

Quiero mostrar el registro en el archivo jni pero obtener el mensaje de error "referencia indefinida a` __android_log_write ".

Mi archivo CMakeLists.txt es:

add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). # Associated headers in the same location as their source # file are automatically included. src/main/cpp/native-lib.cpp ) add_library( # Sets the name of the library. test-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). # Associated headers in the same location as their source # file are automatically included. src/main/cpp/test-lib.cpp ) include_directories( src/main/jni/ ) # Searches for a specified prebuilt library and stores the path as a # variable. Because system libraries are included in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. 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 ) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in the # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. test-lib native-lib # Links the target library to the log library # included in the NDK. ${log-lib} ) 

Y mis dos archivos jni son los mismos que a continuación sin nombre de función

 JNIEXPORT jstring JNICALL Java_com_cyweemotion_www_jnitest_MainActivity_stringFromJNI (JNIEnv *env, jobject){ __android_log_write(ANDROID_LOG_ERROR, "Tag", "Error here"); std::string hello = "Hello from C++"; return env->NewStringUTF(hello.c_str()); }; 

Mi build.gradle (módulo: app) es

  android { compileSdkVersion 23 buildToolsVersion "24.0.3" defaultConfig { minSdkVersion 19 targetSdkVersion 24 versionCode 2 versionName '1.02' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "" } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.config } debug { jniDebuggable false } } externalNativeBuild { cmake { path "CMakeLists.txt" } } productFlavors { } } 

De acuerdo con el documento de Android: Agregar código C y C ++ a su proyecto . Creo que puedo usar log api.

¿Qué hay de malo en mi código o mi configuración?


Actualizar:

He encontrado que no es problema en mi primera biblioteca jni (código de actualización).

Sólo ocurre error en la segunda biblioteca.

Ex: target_link_libraries (test-lib, native-lib , …), native-lib es la segunda librería que se va a cargar.

Así que native-lib no puede usar log api.

Ahora sólo puedo hacer es quitar lib nativo. Sin embargo, realmente quiero saber por qué?

Finalmente encontré que debería separarme para hacer el enlace.

 target_link_libraries( # Specifies the target library. test-lib native-lib # Links the target library to the log library # included in the NDK. ${log-lib} ) target_link_libraries( # Specifies the target library. native-lib # Links the target library to the log library # included in the NDK. ${log-lib} ) 
  • Se produjo un error al agregar a la tabla ref de matrices JNI fijada (1024 entradas)
  • Uso de Fluidsynth para reproducir notas de SoundFonts en Android
  • Android - Directrices JNI
  • ¿Cuál es la mejor manera de guardar JNIEnv *
  • Privilegios raíz para una aplicación Android (aplicación completa, no sólo unos pocos comandos)
  • Extraer código de archivo .aar Android
  • Android JNI nativo C función llamada mata actividad
  • ¿Se ha movido la ubicación de la biblioteca en Android 4.2.1?
  • No se puede hacer JNI llamar desde c ++ a java en android lollipop usando jni
  • Cómo convertir char a jstring en JNI?
  • Compilación de Android JNI para OpenCV en Mac OSX
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.