今天给JNI的C代码添加“__android_log_print”日志打印,发现报错。
这里对原因进行分析
Build command failed.
Error while executing process C:\Users\wanglei\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=D:\learn\AndroidProject\JNIDemo\ccalljava\src\main\jni\Android.mk NDK_APPLICATION_MK=D:\learn\AndroidProject\JNIDemo\ccalljava\src\main\jni\Application.mk APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-26 NDK_OUT=D:/learn/AndroidProject/JNIDemo/ccalljava/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=D:\learn\AndroidProject\JNIDemo\ccalljava\build\intermediates\ndkBuild\debug\lib ccalljava}
[arm64-v8a] Compile : ccalljava <= ccalljava.c
[arm64-v8a] SharedLibrary : libccalljava.so
D:/learn/AndroidProject/JNIDemo/ccalljava/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/ccalljava/ccalljava.o: In function `Java_com_stone_ccalljava_JNI_callbackAdd':
D:/learn/AndroidProject/JNIDemo/ccalljava/src/main/jni/ccalljava.c:28: undefined reference to `__android_log_print'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [D:/learn/AndroidProject/JNIDemo/ccalljava/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/libccalljava.so] Error 1
ndk {
ldLibs "log"
}
LOCAL_PATH :=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE :=ccalljava
LOCAL_SRC_FILES :=ccalljava.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
so文件没有没有添加log的链接库,添加“LOCAL_LDLIBS := -llog”即可