记录一下困扰了2天的问题,心好累。。。
5G时代来了,突然对音视频产生了兴趣,准备大干一场,来一个自学成才~
1、编译了ffmpeg
2、配置了NDK环境
3、新建了项目,拷贝了ffmpeg.a文件及头文件
But。。。。AndroidStudio编译报错了:
Build command failed.
Error while executing process Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build StudioProject/JackiePlayer/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
[1/1] Linking CXX shared library StudioProject/JackiePlayer/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: : && Library/Android/ndk/android-ndk-r17c/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi --gcc-toolchain=/Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=//Library/Android/ndk/android-ndk-r17c/sysroot -fPIC -isystem //Library/Android/ndk/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=26 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -L//StudioProject/JackiePlayer/app/src/main/cpp/libs/armeabi-v7a -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot //Library/Android/ndk/android-ndk-r17c/platforms/android-26/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o //StudioProject/JackiePlayer/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.cpp.o -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale -llog -latomic -lm "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "//Library/Android/ndk/android-ndk-r17c/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" && :
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavcodec
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavfilter
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavformat
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lavutil
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lswresample
//Library/Android/ndk/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lswscale
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
网上各种找资料,全失败。。。
最后经过一步神级(手欠)操作弄好了!!!
发现,Android Studio3.3.0上新建项目的时候,CMakeLists.txt是在app/src/main/cpp/目录下的,把它移到app/目录下以后,编译就通过了。。。应该是在编写CMakeLists.txt的时候,里面的变量地址写的不对,移出来就找到了,还是自己粗心了啊!
CMakeLists.txt移出来以后,记得修改app路径下build.gradle里面CMakeLists.txt的路径,如下:
移出之前:
externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" } }
移出之后:
externalNativeBuild { cmake { path "CMakeLists.txt" } }