Skip to content

Instantly share code, notes, and snippets.

@foundkey
Last active January 17, 2019 11:13
Show Gist options
  • Save foundkey/45f13e494448b2bdbb7662260ace7c83 to your computer and use it in GitHub Desktop.
Save foundkey/45f13e494448b2bdbb7662260ace7c83 to your computer and use it in GitHub Desktop.
设置交叉编译arm原生程序的环境
:: 用于cmake编译arm原生程序前设置环境变量
:: 使用Android SDK自带的cmake工具(cmake官网版本不支持Android平台)
@set path=D:\Android\Sdk\cmake\3.6.4111459\bin;%path%
:: 该文件用于配置NDK的编译工具链
@set TOOLCHAIN_FILE=D:\Android\Sdk\ndk-bundle\build\cmake\android.toolchain.cmake
:: 编译工具
@set MAKE_PROGRAM=D:\Android\Sdk\cmake\3.6.4111459\bin\ninja.exe
:: NDK路径
@set ANDROID_NDK=D:\Android\Sdk\ndk-bundle
:: 以上是通用设置,Android SDK与NDK不修改的情况下,不需要修改
:: 以下是工程的设置,不同工程使用不同的配置
:: 工程名
@set PROJECT_NAME=HelloWorld
:: 编译类型
@set BUILD_TYPE=debug
:: 交叉编译的目标平台
@set ANDROID_ABI=armeabi-v7a
:: 支持Android SDK的最低版本
@set ANDROID_PLATFORM=android-16
:: CMakeLists.txt文件所在的路径
@set CMAKE_HOME=.
:: 编译输出路径
@set BUILD_DIR=.\build\%BUILD_TYPE%
@echo off
call ConfigNDKEnv.bat
cmake -H%CMAKE_HOME% -B%BUILD_DIR% -DANDROID_ABI=%ANDROID_ABI% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DANDROID_NDK=%ANDROID_NDK% -DANDROID_PLATFORM=%ANDROID_PLATFORM% -DCMAKE_CXX_FLAGS=-std=c++11 -DCMAKE_TOOLCHAIN_FILE=%TOOLCHAIN_FILE% -DCMAKE_MAKE_PROGRAM=%MAKE_PROGRAM% -G"Android Gradle - Ninja"
echo Build files have been written to %BUILD_DIR%
pause
@echo off
call ConfigNDKEnv.bat
cmake --build %BUILD_DIR% --target %PROJECT_NAME%
echo Binary files have been written to %BUILD_DIR%
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment