Get the App
SLTechnology News&Howtos  ›  Development  › 

How C++ compiles Android dynamic Library

Shulou Source: shulou.com Published: 2022-05-31 21:51:39 10月01日 Update

This article mainly explains "how C++ compiles Android dynamic library", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how C++ compiles Android dynamic library".

C++ 2.FFmpeg-4.3.2 compiles Android dynamic library (ubuntu 18.04r21b) compilation environment

Linux system:

Ubuntu18.04

NDK

Ndk/android-ndk-r21b

FFmpeg

Ffmpeg-4.3.2

File name after ffmpeg download

Ffmpeg_4.3.2.orig.tar.xz

Decompression mode

Tar xvJf ffmpeg_4.3.2.orig.tar.xz

Operate under root permission

Compiling version 4.3.2 does not need to modify the configure file to write an Android compilation script

Create a new file build_android.sh

#! / bin/bash# ndk path NDK=/home/build/workspace/hqq/vision/vision-app/ndk/android-ndk-r21b# compilation tool chain directory. Clang is used in ndk17 version above. The following is the root directory of the gccTOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64# version number API=21# cross-compilation tree (looking for the corresponding header files and libraries) SYSROOT= "${TOOLCHAIN} / sysroot" # defines the shell method function build_android () {. / configure\-prefix=$PREFIX\-enable-shared\-- disable-static\-- enable-jni\ that executes configure -- enable-gpl\-- enable-small\-- disable-doc\-- disable-programs\-- disable-symver\-- target-os=android\-- arch=$ARCH\-- cpu=$CPU\-- cc=$CC\-- cxx=$CXX\-enable-cross-compile\-- cross-prefix=$CROSS_COMPILE\-- sysroot=$SYSROOT \-- extra-cflags= "- Os-fpic $OPTIMIZE_CFLAGS"\-- extra-ldflags= "\-- disable-asm\ $COMMON_FF_CFG_FLAGS make clean make-j16 make install} # armOUTPUT_FOLDER=armARCH=armCPU=armv7-aTOOL_CPU_NAME=armv7aTOOL_PREFIX=$TOOLCHAIN/bin/$ {TOOL_CPU_NAME}-linux-androideabiOPTIMIZE_CFLAGS="-marm-march=$CPU "PREFIX=$ {PWD} / android/$OUTPUT_FOLDERCROSS_COMPILE=$TOOLCHAIN/bin/arm-linux- Androideabi-CC=$ {TOOL_PREFIX} ${API}-clangCXX=$ {TOOL_PREFIX} ${API}-clang++build_android# arm64 This instruction set supports a minimum of api21OUTPUT_FOLDER=arm64-v8aARCH=aarch64CPU=armv8-aTOOL_CPU_NAME=aarch64TOOL_PREFIX=$TOOLCHAIN/bin/$ {TOOL_CPU_NAME}-linux-androidOPTIMIZE_CFLAGS= "- march=$CPU" PREFIX=$ {PWD} / android/$OUTPUT_FOLDERCROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-android-CC=$ {TOOL_PREFIX} ${API}-clangCXX=$ {TOOL_PREFIX} ${API}-clang++build_android# x86OTUTPUTOEFOLDERY x86ARCHY-86CPU-min x86TOOLY CPUBING i686TOOLPREFIXPREFIXY TOOLCHAING binder ${TOOL_CPU_NAME}-linux-androidOPTIMIZE_CFLAGS= "- march=i686- Mtune=intel-mssse3-mfpmath=sse-M32 "PREFIX=$ {PWD} / android/$OUTPUT_FOLDERCROSS_COMPILE=$TOOLCHAIN/bin/i686-linux-android-CC=$ {TOOL_PREFIX} ${API}-clangCXX=$ {TOOL_PREFIX} ${API}-clang++build_android# x86room64 This instruction set supports a minimum of api21OUTPUT_FOLDER=x86_64ARCH=x86_64CPU=x86-64 tooling CPUBING named names x86-64 TOOLING PREFIXPREFIXINTOOLCHAING ${TOOL_CPU_NAME}-linux-androidOPTIMIZE_CFLAGS= "- march=$CPU-mtune=intel-msse4.2-mpopcnt-M64" # output directory PREFIX=$ {PWD} / android/$OUTPUT_FOLDERCROSS_COMPILE=$TOOLCHAIN/bin/x86_64-linux-android-# so output directory,-- libdir=$LIB_DIR may not be specified # LIB_DIR= "${PWD} / android/libs/$OUTPUT_FOLDER" # compiler CC=$ {TOOL_PREFIX} ${API}-clangCXX=$ {TOOL_PREFIX} ${API}-clang++build_android is generated by default in the $PREFIX/lib directory

Modify file permissions

Chmod 777 build_android.sh

Execute build_android.sh

Can compile "armeabi-v7a", "arm64-v8a", "x86", "x86" 64

If the compilation fails, when you open the file to paste

: set ff # if you look at the file format, you will see fileformat=dos or fileformat=unix

: set ff=unix # set to unix format

: wq # Save exit

Compiled file

Take the .so library and put it in the Android project

Github lib library

Android_ffmpeg_lib

Taxiao213/android_ffmpeg_lib

At this point, I believe you have a deeper understanding of "how C++ compiles Android dynamic library". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Compiling file dynamic directory caching version minimum content instruction method permission format learning support output practical deeper no interest programable Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information NVidia MariaDB Xiaomi