freetype android交叉編譯
阿新 • • 發佈:2021-06-25
專案中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
編譯生成的目標庫