virtualx-engine/platform/android/java/lib/build.gradle
Fredy Huya-Kouadio cb0b2aefc3 Android port of the Godot Editor
These set of changes focus primarily on getting the core logic and overall Godot Editor UI and functionality up and running natively on Android devices.
UI tweaks / cleanup / polish, as well configuration for Android specific functionality / restrictions will be addressed in follow-up PRs iteratively based on feedback.

Co-authored-by: thebestnom <shoval.arad@gmail.com>
2022-03-28 07:54:10 -07:00

163 lines
5.3 KiB
Groovy

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
ext {
PUBLISH_VERSION = getGodotPublishVersion()
PUBLISH_ARTIFACT_ID = 'godot'
}
apply from: "../scripts/publish-module.gradle"
dependencies {
implementation libraries.kotlinStdLib
implementation libraries.androidxFragment
}
def pathToRootDir = "../../../../"
android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
ndkVersion versions.ndkVersion
defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()]
}
namespace = "org.godotengine.godot"
compileOptions {
sourceCompatibility versions.javaVersion
targetCompatibility versions.javaVersion
}
buildTypes {
release_debug {
initWith debug
}
}
flavorDimensions "tools"
productFlavors {
toolsEnabled {}
toolsDisabled {}
}
lintOptions {
abortOnError false
disable 'MissingTranslation', 'UnusedResources'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
// 'doNotStrip' is enabled for development within Android Studio
if (shouldNotStrip()) {
doNotStrip '**/*.so'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['aidl']
assets.srcDirs = ['assets']
}
debug.jniLibs.srcDirs = ['libs/debug']
release_debug.jniLibs.srcDirs = ['libs/release_debug']
release.jniLibs.srcDirs = ['libs/release']
// Tools enabled jni library
toolsEnabledDebug.jniLibs.srcDirs = ['libs/tools/debug']
toolsEnabledRelease_debug.jniLibs.srcDirs = ['libs/tools/release_debug']
toolsEnabledRelease.jniLibs.srcDirs = ['libs/tools/release']
}
libraryVariants.all { variant ->
def flavorName = variant.getFlavorName()
def buildType = variant.buildType.name.capitalize()
if (flavorName == null || flavorName == "") {
throw new GradleException("Invalid product flavor: $flavorName")
}
boolean toolsFlag = flavorName == "toolsEnabled"
def releaseTarget = buildType.toLowerCase()
if (releaseTarget == null || releaseTarget == "") {
throw new GradleException("Invalid build type: " + buildType)
}
// Update the name of the generated library
def outputSuffix = "${releaseTarget}.aar"
if (toolsFlag) {
outputSuffix = "tools.$outputSuffix"
}
variant.outputs.all { output ->
output.outputFileName = "godot-lib.${outputSuffix}"
}
// Find scons' executable path
File sconsExecutableFile = null
def sconsName = "scons"
def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
? [".bat", ".cmd", ".ps1", ".exe"]
: [""])
logger.lifecycle("Looking for $sconsName executable path")
for (ext in sconsExts) {
String sconsNameExt = sconsName + ext
logger.lifecycle("Checking $sconsNameExt")
sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
if (sconsExecutableFile != null) {
// We're done!
break
}
// Check all the options in path
List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
if (!allOptions.isEmpty()) {
// Pick the first option and we're done!
sconsExecutableFile = allOptions.get(0)
break
}
}
if (sconsExecutableFile == null) {
throw new GradleException("Unable to find executable path for the '$sconsName' command.")
} else {
logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
}
for (String selectedAbi : selectedAbis) {
if (!supportedAbis.contains(selectedAbi)) {
throw new GradleException("Invalid selected abi: " + selectedAbi)
}
// Creating gradle task to generate the native libraries for the selected abi.
def taskName = getSconsTaskName(flavorName, buildType, selectedAbi)
tasks.create(name: taskName, type: Exec) {
executable sconsExecutableFile.absolutePath
args "--directory=${pathToRootDir}", "platform=android", "tools=${toolsFlag}", "target=${releaseTarget}", "android_arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors()
}
// Schedule the tasks so the generated libs are present before the aar file is packaged.
tasks["merge${flavorName.capitalize()}${buildType}JniLibFolders"].dependsOn taskName
}
}
// TODO: Enable when issues with AGP 7.1+ are resolved (https://github.com/GodotVR/godot_openxr/issues/187).
// publishing {
// singleVariant("release") {
// withSourcesJar()
// withJavadocJar()
// }
// }
}