项目使用ndk-build而不是Android工作室构建

时间:2015-06-05 21:04:05

标签: android c android-studio android-ndk

当我从命令行使用ndk-build命令构建我的C / C ++库时,它可以工作。

[armeabi] Prebuilt       : libVidyoClientApp.so <= jni/lib/
[armeabi] Install        : libVidyoClientApp.so => libs/armeabi/libVidyoClientApp.so
[armeabi] Compile thumb  : vidyoguestapi <= NCR.JNI.VidyoExports.c
[armeabi] Compile++ thumb: vidyoguestapi <= Ncr.Jni.Wrapper.cpp
In file included from m:/src/projects/java/VideoPlatform/app/src/main/jni/Ncr.Jni.Wrapper.cpp:6:0:
m:/src/projects/java/VideoPlatform/app/src/main/jni/include/Ncr.Jni.Wrapper.h:13:1: warning: 'typedef' was ignored in th
is declaration [enabled by default]
 };
 ^
[armeabi] Compile++ thumb: vidyoguestapi <= NCR.Vidyo.SDK.cpp
In file included from m:/src/projects/java/VideoPlatform/app/src/main/jni/NCR.Vidyo.SDK.cpp:7:0:
m:/src/projects/java/VideoPlatform/app/src/main/jni/include/NCR.Jni.Wrapper.h:13:1: warning: 'typedef' was ignored in th
is declaration [enabled by default]
 };
 ^
[armeabi] StaticLibrary  : libstdc++.a
[armeabi] SharedLibrary  : libvidyoguestapi.so
[armeabi] Install        : libvidyoguestapi.so => libs/armeabi/libvidyoguestapi.so

但是当我尝试在Android studio中构建我的项目时,我收到编译错误:

M:\src\projects\java\VideoPlatform\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/vidyoguestapi/M_\src\projects\java\VideoPlatform\app\src\main\jni\NCR.JNI.VidyoExports.o: In function `Java_com_ncr_mobilevideo_videosdk_VidyoGuestClient_sdkLoginGuest':
M:\src\projects\java\VideoPlatform\app\src\main\jni\NCR.JNI.VidyoExports.c
Error:(50) undefined reference to `VidyoClientInitialize'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [M:\src\projects\java\VideoPlatform\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/libvidyoguestapi.so] Error 1

命令行ndk-build与Android Studio有何不同?

仅供参考:我删除了引用VidyoClientInitialize的行,所有内容都在命令行和Android工作室中构建。所以这似乎是一种环境,但我不确定该看什么

1 个答案:

答案 0 :(得分:2)

目前,Android Studio即时创建了一个新的Android.mk来编译您的C / C ++源代码,忽略了对其他预构建库的所有依赖关系,因为他无法处理它们。

来自AS / gradle的更好的NDK支持应该很快就会出来,但在此期间你可以通过在build.gradle中设置这个来停用它并让它从libs/(armeabi,armeabi-v7a,x86,...)集成你的本机库:

android {
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jniLibs
        jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
    }
}