概要
編譯armv7架構(gòu)的openssl蝌矛、ffmpeg的a碎罚、so庫(kù)欣硼,目前openssl只編譯了靜態(tài)庫(kù)混卵,編譯動(dòng)態(tài)庫(kù)映穗,ffmpeg鏈接openssl編譯的時(shí)候會(huì)出現(xiàn)鏈接的是帶版本號(hào)的openssl動(dòng)態(tài)庫(kù)(如:libcrypto.so.1.1),這樣在Android ndk開(kāi)發(fā)下不能找到.so.1.1的庫(kù)淮菠,而so.1.1格式對(duì)于Android開(kāi)發(fā)不合法男公,所以只編譯opessl靜態(tài)庫(kù)(不會(huì)生成.so.1.1的文件)進(jìn)行解決了,如果有大神有解決方案,可以分享哈枢赔。
環(huán)境要求
- mac
- ndk的環(huán)境配置
注意:腳本權(quán)限chmod -R 文件/文件夾
opessl編譯
- 下載openssl_1_1_1d源碼(可cd到opencssl源碼目錄下執(zhí)行./config)
- 編寫(xiě)腳本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源碼的路徑在同一級(jí)
-
在mac的命令工具界面cd到build_openssl_android.sh所在路徑澄阳,然后直接運(yùn)行./build_openssl_android.sh,成功的話(huà)會(huì)生成一下文件:
FFmpeg編譯
- 下載ffmpeg 4.2.1源碼,在沒(méi)有ffbuid模塊的時(shí)候需要運(yùn)行./configure命令手動(dòng)配置,目前看來(lái)3.xx版本的對(duì)應(yīng)ndk 17、16踏拜、14左右的碎赢,我的是4.2.1版本的對(duì)應(yīng)的是ndk20de 版本,所以其他版本的一下腳本無(wú)法保證速梗。
- ffmpeg的configure文件的相關(guān)修改
- 編譯出來(lái)過(guò)后的.so文件后面會(huì)有一串?dāng)?shù)字肮塞,無(wú)法使用,所以得修改他的命名規(guī)則姻锁,修改的時(shí)候一定要小心空格之類(lèi)的
將該文件中的如:
改前:
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"; }
- 編寫(xiě)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
-
執(zhí)行./build_android_ndk20.sh 枕赵,如果成功,生成如下文件