概要
编译armv7架构的openssl、ffmpeg的a、so库,目前openssl只编译了静态库,编译动态库,ffmpeg链接openssl编译的时候会出现链接的是带版本号的openssl动态库(如:libcrypto.so.1.1),这样在Android ndk开发下不能找到.so.1.1的库,而so.1.1格式对于Android开发不合法,所以只编译opessl静态库(不会生成.so.1.1的文件)进行解决了,如果有大神有解决方案,可以分享哈。
环境要求
- mac
- ndk的环境配置
注意:脚本权限chmod -R 文件/文件夹
opessl编译
- 下载openssl_1_1_1d源码(可cd到opencssl源码目录下执行./config)
- 编写脚本build_openssl_android.sh
#!/bin/bash
sslPath=/Users/chx/Documents/envirment/openssl/openssl-OpenSSL_1_1_1d
NDKPath=/Users/chx/Documents/envirment/android-ndk-r16b
# armeabi
# cd $sslPath
# make clean
# export ARCH=armeabi
# rm -rf ./output-$ARCH
# mkdir ./output-$ARCH
# export ANDROID_NDK=$NDKPath
# export PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin:$PATH
# ./Configure android-arm shared no-ssl2 no-comp no-asm no-idea no-hw no-engine no-dso --prefix=$sslPath/output-$ARCH
# make && make install
# #armeabi-v7a
cd $sslPath
make clean
export ARCH=armeabi-v7a
rm -rf ./output-$ARCH
mkdir ./output-$ARCH
export ANDROID_NDK=$NDKPath
export PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin:$PATH
./Configure android-arm no-shared no-ssl2 no-comp no-asm no-idea no-hw no-engine no-dso --prefix=$sslPath/output-$ARCH
make && make install
# # #arm64-v8a
# cd $sslPath
# make clean
# export ARCH=arm64-v8a
# rm -rf ./output-$ARCH
# mkdir ./output-$ARCH
# export ANDROID_NDK=$NDKPath
# export PATH=$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin:$PATH
# ./Configure android-arm64 -D__ANDROID_API__=23 --prefix=$sslPath/output-$ARCH
# make && make install
-
build_openssl_android.sh的位置与下载的opessl源码的路径在同一级
-
在mac的命令工具界面cd到build_openssl_android.sh所在路径,然后直接运行./build_openssl_android.sh,成功的话会生成一下文件:
FFmpeg编译
- 下载ffmpeg 4.2.1源码,在没有ffbuid模块的时候需要运行./configure命令手动配置,目前看来3.xx版本的对应ndk 17、16、14左右的,我的是4.2.1版本的对应的是ndk20de 版本,所以其他版本的一下脚本无法保证。
- ffmpeg的configure文件的相关修改
- 编译出来过后的.so文件后面会有一串数字,无法使用,所以得修改他的命名规则,修改的时候一定要小心空格之类的
将该文件中的如:
改前:
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'
改后:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
- opessl not found 的解决办法
改前:
enabled openssl && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }
改后:
enabled openssl && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
check_lib openssl openssl/ssl.h OPENSSL_init_ssl -lssl -lcrypto ||
check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }
- 编写build_android_ndk20.sh脚本放入ffmpeg源码文件夹下
#!/bin/bash
export NDK_HOME=/usr/work/ndk/android-ndk-r14b
export PLATFORM_VERSION=android-9
function build
{
echo "start build ffmpeg for $ARCH"
./configure --target-os=linux \
--prefix=$PREFIX --arch=$ARCH \
--disable-doc \
--enable-shared \
--disable-static \
--disable-yasm \
--disable-asm \
--disable-symver \
--enable-gpl \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--cross-prefix=$CROSS_COMPILE \
--enable-cross-compile \
--sysroot=$SYSROOT \
--enable-small \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
echo "build ffmpeg for $ARCH finished"
}
#arm
ARCH=arm
CPU=arm
PREFIX=$(pwd)/android/$ARCH
TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
ADDI_CFLAGS="-marm"
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
#x86
ARCH=x86
CPU=x86
PREFIX=$(pwd)/android/$ARCH
TOOLCHAIN=$NDK_HOME/toolchains/x86-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/i686-linux-android-
ADDI_CFLAGS="-march=i686 -mtune=intel -msse3 -mfpmath=sse -m32"
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
-
执行./build_android_ndk20.sh ,如果成功,生成如下文件