Windows10环境下Android studio NDK编译assimp

1.下载Assimp源码https://github.com/assimp/assimp

2.安装Python2.7并配置环境变量

3.确保电脑有Android SDK和NDK

4.编写编译脚本,保存在assimp源码同级目录下(注,需要根据实际安装路径修改

4.1 make_standalong_toolchain_arm64.bat

python D:/Android/android-ndk-r13b/build/tools/make_standalone_toolchain.py --arch=arm64 --stl=libc++ --api=21 --install-dir=android-toolchain-21-llvm-arm64v8a

4.2 build_assimp_arm64.bat

@echo off
cls

REM *NOTE* Change these based on 
SET ASSIMP_DIR=assimp
SET OUTPUT_DIR=assimp-build-arm64v8a
SET ANDROID_PATH=D:\Android\Sdk
SET NDK_PATH=D:\Android\android-ndk-r13b
SET NDK_TOOLCHAIN=%~dp0android-toolchain-24-llvm-arm64v8a
SET CMAKE_TOOLCHAIN=%NDK_PATH%\build\cmake\android.toolchain.cmake
SET CMAKE_PATH=%ANDROID_PATH%\cmake\3.6.4111459

REM *NOTE* Careful if you don't want rm -rf, I use it for testing purposes.
del %OUTPUT_DIR%
mkdir %OUTPUT_DIR%

REM pushd doesn't seem to work ):<
cd %OUTPUT_DIR%

if not defined ORIGPATH set ORIGPATH=%PATH%
SET PATH=%CMAKE_PATH%\bin;%ANDROID_PATH%\tools;%ANDROID_PATH%\platform-tools;%ORIGPATH%

cmake ^
      -GNinja ^
      -DCMAKE_TOOLCHAIN_FILE=%CMAKE_TOOLCHAIN% ^
      -DASSIMP_ANDROID_JNIIOSYSTEM=ON ^
      -DANDROID_NDK=%NDK_PATH% ^
      -DCMAKE_MAKE_PROGRAM=%CMAKE_PATH%\bin\ninja.exe ^
      -DCMAKE_BUILD_TYPE=Release ^
      -DANDROID_ABI="arm64-v8a" ^
      -DANDROID_NATIVE_API_LEVEL=21 ^
      -DANDROID_FORCE_ARM_BUILD=TRUE ^
      -DCMAKE_INSTALL_PREFIX=install ^
      -DANDROID_STL=gnustl_static ^
	  -DCMAKE_CXX_FLAGS="-Wno-c++11-narrowing -frtti -fexceptions -g -O2" ^
      -DANDROID_TOOLCHAIN=clang ^
      -DBUILD_SHARED_LIBS=OFF ^
      -DASSIMP_BUILD_TESTS=OFF ^

      ../%ASSIMP_DIR%

cmake --build .

cd ..

pause

以上为arm64架构平台的.a库,如果需要编译.so则需要将脚本中的-DBUILD_SHARED_LIBS=OFF 删除即可,编译相关库时需要主要架构和 -DANDROID_STL=gnustl_static,避免所生成的库跟Android studio Android.mk配置的STL一直

5.上面是以arm64-v8a架构为例,对于其他六种架构(armeabi,armeabi-v7a,mips,mips64,x86,x86_64),需要修改–arch参数,该参数选值见下表:


工具链
mips64 编译器 –arch=mips64
mips GCC 4.8 编译器 –arch=mips
x86 GCC 4.8 编译器 –arch=x86
x86_64 GCC 4.8 编译器 –arch=x86_64
arm GCC 4.8 编译器 –arch=arm

 6.分别运行make_standalong_toolchain_arm64.bat和build_assimp_arm64.bat

7.直接将.a文件和头文件移植到安卓工程中,编写Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c++11
LOCAL_MODULE := assimp_static
LOCAL_MODULE_FILENAME := assimp
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libassimp.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include
include $(PREBUILT_STATIC_LIBRARY)

 

你可能感兴趣的:(OpenGL)