Cmake测试被忽略 - 在android中用gradle构建cmake项目

时间:2018-04-20 07:02:24

标签: android c++ gradle android-ndk

我试图将https://github.com/j0r1/JRTPLIB整合到gradle中。已经有关于如何编译库以在Android上安装的自述文件的教程,但我需要gradle集成。

以下是我将项目添加到gradle文件的方式:

https://github.com/lucaszanella/jscam/blob/ecc99f430b360f7e1aa5bf687633a5e3557c045e/src/jscam/android/app/build.gradle#L118

我收到编译错误,因为我的系统库不支持ifaddrs。但是,该项目的密码学家对此进行了测试:

jrtplib_include_test(ifaddrs.h RTP_SUPPORT_IFADDRS "// No ifaddrs support")

那么为什么gradle试图建立一些没有通过测试的东西呢?

编译我的应用时出现错误:

Error while executing '/android-sdk-linux/cmake/3.6.4111459/bin/cmake' with arguments {--build /home/project/src/jscam/android/app/.externalNativeBuild/cmake/debug/x86 --target jrtplib-shared}
  [1/3] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpudpv4transmitter.cpp.o
  [2/3] Building CXX object src/CMakeFiles/jrtplib-shared.dir/rtpudpv6transmitter.cpp.o
  FAILED: /android-sdk-linux/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/android-sdk-linux/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/android-sdk-linux/ndk-bundle/sysroot  -DJRTPLIB_COMPILING -Djrtplib_shared_EXPORTS -I/home/project/src/jscam/JRTPLIB/src -Isrc -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward-isystem /android-sdk-linux/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=16 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -fPIC -MD -MT src/CMakeFiles/jrtplib-shared.dir/rtpudpv6transmitter.cpp.o -MF src/CMakeFiles/jrtplib-shared.dir/rtpudpv6transmitter.cpp.o.d -o src/CMakeFiles/jrtplib-shared.dir/rtpudpv6transmitter.cpp.o -c /home/project/src/jscam/JRTPLIB/src/rtpudpv6transmitter.cpp
  /home/project/src/jscam/JRTPLIB/src/rtpudpv6transmitter.cpp:1575:2: error: use of undeclared identifier 'getifaddrs'
          getifaddrs(&addrs);
          ^
  /home/project/src/jscam/JRTPLIB/src/rtpudpv6transmitter.cpp:1588:2: error: use of undeclared identifier 'freeifaddrs'
          freeifaddrs(addrs);
          ^
  2 errors generated.
  FAILED: /android-sdk-linux/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/android-sdk-linux/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/android-sdk-linux/ndk-bundle/sysroot  -DJRTPLIB_COMPILING -Djrtplib_shared_EXPORTS -I/home/project/src/jscam/JRTPLIB/src -Isrc -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem /android-sdk-linux/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward-isystem /android-sdk-linux/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=16 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security   -O0 -fno-limit-debug-info  -fPIC -MD -MT src/CMakeFiles/jrtplib-shared.dir/rtpudpv4transmitter.cpp.o -MF src/CMakeFiles/jrtplib-shared.dir/rtpudpv4transmitter.cpp.o.d -o src/CMakeFiles/jrtplib-shared.dir/rtpudpv4transmitter.cpp.o -c /home/project/src/jscam/JRTPLIB/src/rtpudpv4transmitter.cpp
  /home/project/src/jscam/JRTPLIB/src/rtpudpv4transmitter.cpp:1813:2: error: use of undeclared identifier 'getifaddrs'
          getifaddrs(&addrs);
          ^
  /home/project/src/jscam/JRTPLIB/src/rtpudpv4transmitter.cpp:1826:2: error: use of undeclared identifier 'freeifaddrs'
          freeifaddrs(addrs);
          ^
  2 errors generated.
  ninja: build stopped: subcommand failed.

1 个答案:

答案 0 :(得分:1)

Android NDK为您<ifaddrs.h>。但缺少的功能,如 getifaddrs(),可用于__ANDROID_API__ 24 及更高版本,而您的项目设置 __ ANDROID_API __ = 16

如果您的资料库将与24以下的 minSdkVersion 一起使用,则无法使用这些功能。遗憾的是,JRTPLIB似乎并没有对ifaddrs提供如此精细的支持,但是如果您选择,可以强行关闭 RTP_SUPPORT_IFADDRS