Прежде всего, я довольно новичок в построении нативного кода на Android и C ++ в целом, поэтому, возможно, мне не хватает чего-то очень очевидного для более опытных разработчиков ...
Я работаю в приложении Android, которое использует Oboe для обработки звука. Пока все это работает, я установил NDK, добавил CMakeLists.txt, скомпилировал мой код и запустил приложение, все в порядке.
Теперь я попытался интегрировать FFmpeg в свой проект, выполнив шаги, описанные в этой статье: Использование FFmpeg для более быстрого декодирования звука . Я скомпилировал FFmpeg, используя предоставленный там скрипт, и переместил файлы в указанные папки. Я внес изменения в свой CMakeList.txt, чтобы иметь возможность использовать скомпилированные файлы FFmpeg, и в среде IDE все выглядит отлично.
Но мои сборки ломаются с этой ошибкой:
Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnative
Я провел несколько поисков в Google и исследовал эту проблему, но, похоже, не могу понять. Не уверен, что именно здесь не хватает и где его взять ... Любая помощь очень ценится!
Вот мой CMakeList.txt
set(FFMPEG_DIR /volumes/work/repos/android/ffmpeg/build/${ANDROID_ABI})
include_directories(src/main/cpp/)
include_directories(native-lib ${FFMPEG_DIR}/include)
add_library(avformat SHARED IMPORTED)
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION
${FFMPEG_DIR}/lib/libavformat.so)
add_library(avutil SHARED IMPORTED)
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION
${FFMPEG_DIR}/lib/libavutil.so)
add_library(avcodec SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION
${FFMPEG_DIR}/lib/libavcodec.so)
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION
${FFMPEG_DIR}/lib/libswresample.so)
add_library(native-lib
SHARED
src/main/cpp/native-lib.cpp
src/main/cpp/AudioEngine.cpp
src/main/cpp/DataSource.h
src/main/cpp/StorageDataSource.cpp
src/main/cpp/LockFreeQueue.h
src/main/cpp/logging.h
src/main/cpp/NDKExtractor.cpp
src/main/cpp/Constants.h
src/main/cpp/OpenGLFunctions.cpp
src/main/cpp/Player.cpp
src/main/cpp/Mixer.h
src/main/cpp/IRenderableAudio.h
src/main/cpp/UtilityFunctions.cpp
src/main/cpp/FFMpegExtractor.h
src/main/cpp/FFMpegExtractor.cpp
)
set(TARGET_LIBS log android oboe GLESv2)
set(TARGET_LIBS ${TARGET_LIBS} native avformat avutil avcodec swresample)
target_link_libraries(native-lib ${TARGET_LIBS})
#set(CMAKE_CXX_STANDARD 14)
# Set the path to the Oboe directory.
set(OBOE_DIR /Volumes/Work/Repos/Android/oboe-test/oboe)
# Add the Oboe library as a subdirectory.
add_subdirectory(${OBOE_DIR} ./oboe)
# Specify the path to the Oboe header files.
include_directories(${OBOE_DIR}/include)
И это конечная часть нативного вывод журнала задачи сборки (полный журнал слишком велик для публикации):
Build native-lib_armeabi-v7a
(...)
[38/41] /Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DOBOE_ENABLE_LOGGING=1 -Dnative_lib_EXPORTS -I../../../../src/main/cpp -I../../../../native-lib -I/volumes/work/repos/android/ffmpeg/build/armeabi-v7a/include -I/Volumes/Work/Repos/Android/oboe-test/oboe/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/Player.cpp.o -MF CMakeFiles/native-lib.dir/src/main/cpp/Player.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/Player.cpp.o -c /Volumes/Work/Repos/Android/MyApp/app/src/main/cpp/Player.cpp
[39/41] /Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DOBOE_ENABLE_LOGGING=1 -Dnative_lib_EXPORTS -I../../../../src/main/cpp -I../../../../native-lib -I/volumes/work/repos/android/ffmpeg/build/armeabi-v7a/include -I/Volumes/Work/Repos/Android/oboe-test/oboe/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/UtilityFunctions.cpp.o -MF CMakeFiles/native-lib.dir/src/main/cpp/UtilityFunctions.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/UtilityFunctions.cpp.o -c /Volumes/Work/Repos/Android/MyApp/app/src/main/cpp/UtilityFunctions.cpp
[40/41] /Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DOBOE_ENABLE_LOGGING=1 -Dnative_lib_EXPORTS -I../../../../src/main/cpp -I../../../../native-lib -I/volumes/work/repos/android/ffmpeg/build/armeabi-v7a/include -I/Volumes/Work/Repos/Android/oboe-test/oboe/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/FFMpegExtractor.cpp.o -MF CMakeFiles/native-lib.dir/src/main/cpp/FFMpegExtractor.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/FFMpegExtractor.cpp.o -c /Volumes/Work/Repos/Android/MyApp/app/src/main/cpp/FFMpegExtractor.cpp
[41/41] : && /Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/AudioEngine.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/StorageDataSource.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/NDKExtractor.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/OpenGLFunctions.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/Player.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/UtilityFunctions.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/FFMpegExtractor.cpp.o -llog -landroid oboe/liboboe.a -lGLESv2 -lnative /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavformat.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavutil.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavcodec.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libswresample.so -llog -lOpenSLES -latomic -lm && :
FAILED: : && /Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi21 --gcc-toolchain=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++14 -frtti -fexceptions -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/AudioEngine.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/StorageDataSource.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/NDKExtractor.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/OpenGLFunctions.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/Player.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/UtilityFunctions.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/FFMpegExtractor.cpp.o -llog -landroid oboe/liboboe.a -lGLESv2 -lnative /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavformat.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavutil.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libavcodec.so /volumes/work/repos/android/ffmpeg/build/armeabi-v7a/lib/libswresample.so -llog -lOpenSLES -latomic -lm && :
/Users/myuserfolder/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lnative
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.