Android NDK - Android studio gradle undefined reference to __android_log_write -
Android NDK - Android studio gradle undefined reference to __android_log_write -
i trying debug jni c function inserting log messages, can't work. start trying modify hello-jni illustration comes android studio. modified code:
#include <string.h> #include <jni.h> #include <android/log.h> jstring java_com_example_hellojni_hellojni_stringfromjni( jnienv* env, jobject thiz ) { #if defined(__arm__) #if defined(__arm_arch_7a__) #if defined(__arm_neon__) #if defined(__arm_pcs_vfp) #define abi "armeabi-v7a/neon (hard-float)" #else #define abi "armeabi-v7a/neon" #endif #else #if defined(__arm_pcs_vfp) #define abi "armeabi-v7a (hard-float)" #else #define abi "armeabi-v7a" #endif #endif #else #define abi "armeabi" #endif #elif defined(__i386__) #define abi "x86" #elif defined(__x86_64__) #define abi "x86_64" #elif defined(__mips64) /* mips64el-* toolchain defines __mips__ */ #define abi "mips64" #elif defined(__mips__) #define abi "mips" #elif defined(__aarch64__) #define abi "arm64-v8a" #else #define abi "unknown" #endif __android_log_write(android_log_error, "test_tag", "error here"); homecoming (*env)->newstringutf(env, "hello jni ! compiled abi " abi "."); }
and android.mk file:
local_path := $(call my-dir) include $(clear_vars) local_module := hello-jni local_src_files := hello-jni.c local_ldflags := -llog include $(build_shared_library)
when utilize ndk-build
script libhello-jni.so files built no problem. when seek build project in android studio next gradle error message
information:gradle tasks [:app:assembledebug] :app:prebuild :app:compiledebugndk c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/c_\android\projects\hello-jni\app\src\main\jni\hello-jni.o: in function `java_com_example_hellojni_hellojni_stringfromjni': hello-jni.c:(.text.java_com_example_hellojni_hellojni_stringfromjni+0x24): undefined reference `__android_log_write' error:error: ld returned 1 exit status make.exe: *** [c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/libhello-jni.so] error 1 error:execution failed task ':app:compiledebugndk'. > com.android.ide.common.internal.loggederrorexception: failed run command: c:\android\android-ndk-r10c\ndk-build.cmd ndk_project_path=null app_build_script=c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\android.mk app_platform=android-19 ndk_out=c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\obj ndk_libs_out=c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\lib app_abi=all error code: 2 output: c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/hello-jni/c_\android\projects\hello-jni\app\src\main\jni\hello-jni.o: in function `java_com_example_hellojni_hellojni_stringfromjni': hello-jni.c:(.text.java_com_example_hellojni_hellojni_stringfromjni+0x24): undefined reference `__android_log_write' collect2.exe: error: ld returned 1 exit status make.exe: *** [c:\android\projects\hello-jni\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/libhello-jni.so] error 1 information:build failed information:total time: 3.297 secs information:2 errors information:0 warnings information:see finish output in console
i've tried suggestions given in question, still same error: what log api phone call android jni program?
what doing wrong?
i'm using android studio 0.8.9 , ndk r10c.
i found reply after bit more searching.
if build .so files using ndk-build
script on command line , add
sourcesets.main { jni.srcdirs = [] jnilibs.srcdir 'src/main/libs' }
into build.gradle file gradle doesn't seek build .so files works. looks problem android studio-gradle-ndk integration?
i found reply here http://stackoverflow.com/a/21111458/4182796
android-studio gradle android-ndk linker-error android.mk
Comments
Post a Comment