项目中Opencv需要显示中文,由于本身并不支持,所以需要借助第三方的库freetype来实现。这个库虽然android本身也有使用,但并没有暴露接口给外部使用。
编译环境
- wsl ubuntu 20.04
- freetype 2.10.4
- ndk-r17c
freetype下载地址,这里使用最新版本2.10.4
arm64-v8a编译脚本
#!/bin/bash
make clean
NDK=/mnt/e/Android/android-ndk-r17c-linux-x86_64/android-ndk-r17c
TOOLCHAIN=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
SYSROOT=$NDK/platforms/android-21/arch-arm64
CPU=armv64-v8a
PREFIX=$(pwd)/android/$CPU
function build
{
./configure --host=aarch64-linux-android --prefix=$PREFIX --enable-shared --enable-static --with-zlib=no --with-bzip2=no --with-png=no --with-harfbuzz=no --with-sysroot=$SYSROOT
make -j8
make install
}
build
编译过程:
注意别忘了加make install, 否则不会把生成的库拷贝到Prefix目录中。
当然也可以同时编译arm和arm64-v8a, 参考地址
#!/bin/bash
NDK=/mnt/e/Android/android-ndk-r17c-linux-x86_64/android-ndk-r17c
function configure
{
CPU=$1
PREFIX=$(pwd)/android/$CPU
TOOLCHAIN=""
SYSROOT=""
HOST=""
if [ "$CPU" == "armv7a" ]
then
TOOLCHAIN=$NDK/toolchains/arm-linux-android-4.9/prebuilt/linux-x86_64
SYSROOT=$NDK/platforms/android-21/arch-arm/
HOST=arm-linux-androideabi
else
TOOLCHAIN=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
SYSROOT=$NDK/platforms/android-21/arch-arm64/
HOST=aarch64-linux-android
fi
export PATH=$TOOLCHAIN:$PATH
./configure --with-png=no --with-zlib=no --host=$HOST --prefix=$PREFIX --with-sysroot=$SYSROOT
}
build()
{
make clean
cpu=$1
echo "build $cpu"
configure $cpu
echo "configure done. CFLAGS:$CFLAGS\n PATH:$PATH"
echo "start make..."
make -j8
echo "make done."
echo "start make install..."
make install
echo "make install done."
}
build arm64
build armv7a
编译生成的目标库