В случае, если вы хотите использовать Gradle для настройки вашего cmake ...
Я использую Gradle Wrapper, после установки gradle вы можете вызвать gradle wrapper
в каталоге иэто установит локальную копию.Эта копия может быть установлена в определенной версии или может быть обновлена .
Плагин Android Gradle использует систему сборки ninja для настройки cmake и целевых ABI.Следующие скрипты будут генерировать ABI для всех поддерживаемых типов платформ, но легко удалить любой, который вы не хотите создавать.
VSCode имеет плагин gradle для генерации из IDEили вы можете создать тип сборки, который просто вызывает командную строку gradlew.
Сначала я инициировал проект gradle, используя gradle wrapper
, а затем gradlew init
.
Затем ядобавлены сценарии сборки для создания библиотеки Android.
build.gradle
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds/
*/
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 28 // Change this to the SDK version you have installed
buildToolsVersion '28.0.3' // Change this to the SDK build tools you have installed
defaultConfig {
minSdkVersion 16 // Cannot be less than 16
targetSdkVersion 28 // Same as CompileSdkVersion
versionCode 1
versionName "1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
}
}
ndk {
abiFilters = []
abiFilters.addAll(ABI_FILTERS.split(';').collect { it as String })
}
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-16',
'-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static',
'-DANDROID_CPP_FEATURES=rtti exceptions'
}
}
}
externalNativeBuild {
cmake {
path './CMakeLists.txt'
}
}
buildTypes {
release {
minifyEnabled false
}
debug {
debuggable true
jniDebuggable true
minifyEnabled false
}
}
}
Этот файл сборки включает в себя фиктивный файл AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="16" />
<application/>
</manifest>
Мне нужна была более старая версия CMake, я выбрал 3.4 вместо 3.11
CMakeLists.txt
cmake_minimum_required( VERSION 3.4.0 )
add_library( Engine SHARED main.cpp )
local.properties
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
ndk.dir=d\:\\android\\ndk
sdk.dir=d\:\\android\\sdk
gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# EDIT THIS LINE to change the Target ABIs
ABI_FILTERS=x86;x86_64;armeabi-v7a;arm64-v8a
org.gradle.java.home=D:\\Program Files\\Java\\jdk8
distributionUrl=\
https\://services.gradle.org/distributions/gradle-4.1-all.zip
# When set to true the Gradle daemon is used to run the build. For local developer builds this is our favorite property.
# The developer environment is optimized for speed and feedback so we nearly always run Gradle jobs with the daemon.
org.gradle.daemon=true
Наконец, для сборки я просто запускаю:
.\gradlew :externalNativeBuildDebug
или
.\gradlew :externalNativeBuildRelease
И он генерирует библиотеки в каталоге build\intermediates\cmake
.