Assimp cross-compiles Android and iOS libraries

Crop based on Assimp 5.0.1 Release, only retain 3D model analysis in OBJ and FBX formats, and use cross-compilation toolchain to compile into Android and iOS libraries

Link to this article

compile

  • Compile the Android static library:

    ①Remember to modify the top MY_NDK, MY_SDK, MY_CMAKE path in build_for_android.sh, and change it to your corresponding installation path

    ② Execute build_for_android.sh, and finally generate static libraries for Android platform arm64-v8a and armeabi-v7a

  • Compile the iOS static library:

    ① Execute build_for_android.sh, and finally generate a static library for the iOS platform. The default compilation is all (including armv7, armv7s, arm64)

expand

  • If you want to support more format parsing, copy the source file in the corresponding format directory of Assimp 5.0.1 and register it in ImporterRegistry.cpp
  • If you want to support more post-processing, copy the corresponding post-processing source file and register it in PostStepRegistry.cpp

See AssimpLib for the precompiled Android and iOS libraries
. The precompiled library is in the pre_build directory. 3D model analysis only supports OBJ and FBX formats, and post-processing only supports FlipUVsProcess and TriangulateProcess
insert image description here

Android compilation script

#!/bin/sh

# 记得改成自己的 NDK、SDK 路径,以及 CMake 版本
MY_NDK="/Users/AlanWang/AndroidDev/android-ndk-r16b"
MY_SDK="/Users/AlanWang/AndroidDev/sdk"
MY_CMAKE="${MY_SDK}/cmake/3.10.2.4988404/bin/cmake"

OUTPUT_LIBS="./build/libs/android"

function build_with_armeabi() {
    
    
	ARME_ABI=$1
	API_LEVEL=$2
	PLATFORM="android-${API_LEVEL}"
	echo ${ARME_ABI}
	echo ${PLATFORM}

	BUILD_DIR="./build/android/${ARME_ABI}"
	PRE_EXE_DIR=$(pwd)
	echo ${PRE_EXE_DIR}

	# 使用 android 工具链生成 makefile
	${MY_CMAKE} \
	-H"./" \
	-B"${BUILD_DIR}" \
	-DANDROID_ABI="${ARME_ABI}" \
	-DANDROID_NDK="${MY_NDK}" \
	-DCMAKE_LIBRARY_OUTPUT_DIRECTORY="./build/android/libs/${ARME_ABI}" \
	-DCMAKE_BUILD_TYPE="Release" \
	-DCMAKE_TOOLCHAIN_FILE="${MY_NDK}/build/cmake/android.toolchain.cmake" \
	-DANDROID_PLATFORM=${PLATFORM} \
	-DANDROID_TOOLCHAIN="clang" \
	-DCMAKE_C_FLAGS="-fpic -fexceptions -frtti" \
	-DCMAKE_CXX_FLAGS="-fpic -fexceptions -frtti" \
	-DANDROID_STL="c++_static" \

	# 生成目标文件
	cd ${BUILD_DIR}
	make

	# 将目标文件移至指定目录
	cd ${PRE_EXE_DIR}
	mkdir -p ${OUTPUT_LIBS}/${ARME_ABI}/
	mv ${BUILD_DIR}/libs/* ${OUTPUT_LIBS}/${ARME_ABI}/
	rm -r ./build/android
}

build_with_armeabi armeabi-v7a 16
build_with_armeabi arm64-v8a 21

iOS compile script

#!/bin/sh

OUTPUT_LIBS="./build/libs/ios"

function build_with_platform_and_armeabi() {
    
    
	PLATFORM=$1
	ARME_ABI=$2
	echo ${PLATFORM}
	echo ${ARME_ABI}

	BUILD_DIR="./build/ios/${ARME_ABI}"
	PRE_EXE_DIR=$(pwd)
	echo ${PRE_EXE_DIR}

	cmake \
	-H"./" \
	-B"${BUILD_DIR}" \
	-DCMAKE_BUILD_TYPE="Release" \
	-DCMAKE_TOOLCHAIN_FILE="./toolchain/ios.toolchain.cmake" \
	-DIOS_PLATFORM=${PLATFORM} \
	-DCMAKE_C_FLAGS="-fpic -fexceptions -frtti" \
	-DCMAKE_CXX_FLAGS="-fpic -fexceptions -frtti -std=c++11 -stdlib=libc++" \
#	-DIOS_ARCH=${ARME_ABI} \

	# 生成目标文件
	cd ${BUILD_DIR}
	make

	# 将目标文件移至指定目录
	cd ${PRE_EXE_DIR}
	mkdir -p ${OUTPUT_LIBS}/${ARME_ABI}/
	mv ${BUILD_DIR}/libs/* ${OUTPUT_LIBS}/${ARME_ABI}/
	rm -r ./build/ios
}

build_with_platform_and_armeabi "OS" "all"

#build_with_platform_and_armeabi "OS" "armv7"
#build_with_platform_and_armeabi "OS" "armv7s"
#build_with_platform_and_armeabi "OS" "arm64"
#
#build_with_platform_and_armeabi "SIMULATOR64" "x86_64"
#build_with_platform_and_armeabi "SIMULATOR" "i386"

Guess you like

Origin blog.csdn.net/u011520181/article/details/120835360
Recommended