I am using Android Studio 2.2 and cmake to create a jni file.
I want to show the log of the jni file, but get the error message "undefined link to` __android_log_write".
My CMakeLists.txt file:
add_library(
And my two jni files are the same as below, without function name
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()); };
My build.gradle (Module: app)
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 { } }
According to android document: add C and C ++ code to your project . I think I can use log api.
What is wrong with my code or my setup?
Update:
I found that this is not a problem in my first jni library (update code).
This is only a mistake in the second library.
ex: target_link_libraries (test-lib, native-lib , ...), native-lib is the second loadable library.
So native-lib cannot use log api.
Now I can only remove native-lib. However, I really want to know why?