Android平臺OpenGL ES/Assimp/OpenCV/GLM整合說明
本文程式碼見: https://github.com/jiangxincode/DroidDemo
整合Assimp
- 下載Assimp 5.0.1版本:https://codeload.github.com/assimp/assimp/zip/refs/tags/v5.0.1
- 解壓後本地目錄為
D:\Code\temp\assimp-5.0.1
- 將
scripts\android_crosscompile\make_android.bat
拷貝為scripts\android_crosscompile\make_android_self_defined.bat
- 將
scripts\android_crosscompile\make_android_self_defined.bat
中的內容進行自定義配置,我的配置如下:
@echo off
set ASSIMP_PATH=D:\Code\temp\assimp-5.0.1
set CMAKE_PATH="C:\Users\jiangxin\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe"
set ANDROID_NDK_PATH=C:\Users\jiangxin\AppData\Local\Android\Sdk\ndk\22.0.7026061
set ANDROID_CMAKE_PATH=C:\Users\jiangxin\AppData\Local\Android\Sdk\ndk\22.0.7026061\build\cmake
pushd %ASSIMP_PATH%
rmdir /s /q build
mkdir build
cd build
%CMAKE_PATH% .. ^
-G"MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_CXX_FLAGS_RELEASE="%CMAKE_CXX_FLAGS_RELEASE% -Os -Wall -s" ^
-DCMAKE_TOOLCHAIN_FILE=%ANDROID_CMAKE_PATH%\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^
-DANDROID_NDK=%ANDROID_NDK_PATH% ^
-DANDROID_NATIVE_API_LEVEL=android-16 ^
-DASSIMP_ANDROID_JNIIOSYSTEM=ON ^
-DANDROID_ABI=arm64-v8a ^
-DASSIMP_BUILD_ZLIB=ON ^
-DASSIMP_BUILD_TESTS=OFF ^
-DASSIMP_BUILD_ASSIMP_TOOLS=OFF ^
-DASSIMP_NO_EXPORT=ON
%CMAKE_PATH% --build .
popd
- 執行如下編譯命令:
cd D:\Code\temp\assimp-5.0.1\scripts\android_crosscompile
.\make_android_self_defined.bat
- 將
assimp-4.1.0\build\codelibassimp.so
放到app\libs\
- 將
assimp-4.1.0\include
中的目錄放到app\src\main\cpp\include
- 將
assimp-4.1.0\build\include\assimp\config.h
拷貝到app\src\main\cpp\assimp-4.1.0\include\assimp
整合OpenCV
OpenCV的整合比較簡單,官網提供了Android平臺所需的動態庫和C++標頭檔案。
- 下載OpenCV 4.5.1版本:https://cfhcable.dl.sourceforge.net/project/opencvlibrary/4.5.1/opencv-4.5.1-android-sdk.zip
- 解壓後本地目錄為
D:\Code\temp\opencv-4.5.1-android-sdk
- 將
OpenCV-android-sdk\sdk\native\libs\arm64-v8a\libopencv_java4.so
拷貝到app\libs\
- 將
OpenCV-android-sdk\sdk\native\jni\include
中的內容拷貝到app\src\main\cpp\include
整合GLM
GLM的整合就更簡單了,原始碼都是hpp檔案(即定義和實現在同一個檔案中)。
- 下載GLM 0.9.9.8版本:https://github.com/g-truc/glm/archive/refs/tags/0.9.9.8.zip
- 解壓後本地目錄為
D:\Code\temp\glm-0.9.9.8
- 將
glm-0.9.9.8\glm
中的內容拷貝到app\src\main\cpp\include
參考
- Android: Use Assimp to load a 3D model: http://www.anandmuralidhar.com/blog/android/assimp/
- AssimpAndroid: https://github.com/anandmuralidhar24/AssimpAndroid
- 使用Android Studio+CMakeLists編譯assimp: https://blog.csdn.net/u010302327/article/details/104473671
- TestAssimp: https://blog.csdn.net/u010302327/article/details/104473671
- Assimp編譯實錄: https://blog.csdn.net/fyfcauc/article/details/72627996