我有这个项目
我正在尝试使用CMakeLists构建C的源代码:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
rtmp-jni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${CMAKE_SOURCE_DIR}/src/main/cpp/rtmp-jni.c)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../jnisource"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/includes/openssl"
"${CMAKE_CURRENT_SOURCE_DIR}/../jnisource/librtmp")
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
rtmp-jni
# Links the target library to the log library
# included in the NDK.
${log-lib} )
构建APK时,出现此错误:
Build command failed.
Error while executing process /Users/kevinabrioux/android-sdks/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target rtmp-jni}
[1/1] Linking C shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so
FAILED: : && /Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi --gcc-toolchain=/Users/kevinabrioux/android-sdks/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/kevinabrioux/android-sdks/ndk-bundle/sysroot -fPIC -isystem /Users/kevinabrioux/android-sdks/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot /Users/kevinabrioux/android-sdks/ndk-bundle/platforms/android-21/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,librtmp-jni.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/librtmp-jni.so CMakeFiles/rtmp-jni.dir/src/main/cpp/rtmp-jni.c.o -llog -lm && :
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:14: error: undefined reference to 'RTMP_Alloc'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:20: error: undefined reference to 'RTMP_Init'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:21: error: undefined reference to 'RTMP_SetupURL'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_Connect'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:26: error: undefined reference to 'RTMP_ConnectStream'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:35: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:36: error: undefined reference to 'RTMP_Free'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:54: error: undefined reference to 'RTMP_Read'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:75: error: undefined reference to 'RTMP_Pause'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:84: error: undefined reference to 'RTMP_IsConnected'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:93: error: undefined reference to 'RTMP_IsTimedout'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:99: error: undefined reference to 'RTMP_Close'
/Users/kevinabrioux/Documents/Android-video/ReadyPlayerOne/app/src/main/cpp/rtmp-jni.c:100: error: undefined reference to 'RTMP_Free'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
我该怎么做才能使我的项目在这些对象上找到参考?
答案 0 :(得分:0)
您的\\+
必须包含 librtmp 。您无需将其作为项目的一部分进行构建。完全可以使用该库随附的make文件制作一次,并将其引用为IMPORTED,例如
target_link_libraries