转载请注明:https://www.jianshu.com/p/ab6622a34246
最近开发得项目中需要用到FF,就去下载最新的代码,我用的是4.1
remotes/origin/release/4.1
下载之后又去下载了最新的NDK:android-ndk-r19c
开始编译后问题不少,网上搜索的编译脚本大部分都是基于GCC编译的,但是最新的NDK中GCC已去掉,只能使用clang来编译。
如下是编译脚本
#!/bin/bash
NDK=/home/cc/android-ndk-r19c
myarch=$1
if [ -z $myarch ]
then
myarch=arm64
fi
echo $__ANDROID_API__
if [ "$myarch" == "arm64" ]
then
target_host=aarch64-linux-android
target_host2=aarch64-linux-android
elif [ "$myarch" == "arm" ]
then
target_host=arm-linux-androideabi
target_host2=armv7a-linux-androideabi
else
target_host=aarch64-linux-android
target_host2=aarch64-linux-android
fi
echo $target_host
PREFIX=../output/$myarch
ANDROID_API=21
#aarch64-linux-android-strip
#target_host=aarch64-linux-android
CC_name=$ANDROID_API-clang
CXX_name=$ANDROID_API-clang++
#export AR=$target_host-ar
#export LD=$target_host-ld
#export STRIP=$target_host-strip
#export AS=$target_host2-as
export CC=$target_host2$CC_name
export CXX=$target_host2$CXX_name
#SYSROOT=$NDK/platforms/android-$ANDROID_API/arch-$myarch
SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
echo "CC "$CC
function build_ff_for_android
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--enable-small \
--disable-asm \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-symver \
--disable-manpages \
--disable-programs \
--disable-avdevice \
--disable-muxers \
--disable-filters \
--arch=$myarch \
--enable-cross-compile \
--target-os=android \
--strip=$STRIP \
--cross-prefix=$target_host- \
--cc=$CC --cxx=$CXX \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic -DBIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j4
make install
#--ar=$AR --ld=$LD --strip=$STRIP --as=$AS \
}
cd ffmpeg
build_ff_for_android
第一类问题:
遇到的很多路径找不到的问题,比如clang找不到,
CC_name=28-clang
CXX_name=28-clang++
这两个变量就是为了配置clang的路径设置的。
第二类问题:
CC libavdevice/v4l2.o
libavdevice/v4l2.c:135:9: error: assigning to 'int (*)(int, unsigned long, ...)' from incompatible type '<overloaded function type>'
SET_WRAPPERS();
^~~~~~~~~~~~~~
libavdevice/v4l2.c:121:17: note: expanded from macro 'SET_WRAPPERS'
s->ioctl_f = prefix ## ioctl; \
^ ~~~~~
/home/cc/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/bits/ioctl.h:56:5: note: candidate function has type mismatch at 2nd parameter
(expected 'unsigned long' but has 'unsigned int')
int ioctl(int __fd, unsigned __request, ...) __overloadable __enable_if(1, "") __RENAME(ioctl);
^
/home/cc/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/bits/ioctl.h:36:5: note: candidate function has type mismatch at 2nd parameter
(expected 'unsigned long' but has 'int')
int ioctl(int __fd, int __request, ...);
^
1 error generated.
make: *** [ffbuild/common.mak:60: libavdevice/v4l2.o] Error 1
该错误表示函数指针类型不正确。
man一下系统的ioctl函数,跟报错的指针类型是一致的,说明这里没有引用标准的ioctl.h
后来查到NDK中该函数的定义
toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/bits/ioctl.h
解决办法就是在编译脚本中添加了宏:BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
#################2020-08-13更新###################
遇到了几个问题,
需要编译不同的架构版本,添加了两个参数arm和arm64,
用法:./build.sh arm64
如果不带参数,会编译arm64。在低版本android机器上运行,会提示库或者方法找不到,如下:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libcamera2ndk.so" not found
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "iconv_close" referenced by "/data/app/com.udx.player.default-fNOzMQQ2UEz-wXtlcReA3Q==/lib/arm64/libavcodec.so"...
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1657)
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "fgets_unlocked" referenced by "/data/app/com.udx.player.default-oaYAVLjyHVdCkqyxaK0fDw==/lib/arm64/libavfilter.so"...
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1657)
我在android 6.0上运行,就会出现如上问题,因为我依赖的NDK版本比较高,所以将NDK高版本中的一些安卓库给编译进去了,解决方式就是使用低版本的clang
ANDROID_API=21
CC_name=$ANDROID_API-clang
CXX_name=$ANDROID_API-clang++