godot/platform/android/java/lib/build.gradle
Fredia Huya-Kouadio 30e3e301e0 Update the gradle build tasks to generate play store builds.
Configure the gradle builds to sign and build the release version of the Godot Android Editor
2023-04-27 22:13:00 -07:00

174 lines
5.5 KiB
Groovy

plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
ext {
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
}
kotlinOptions {
jvmTarget = versions.javaVersion
}
buildTypes {
dev {
initWith debug
}
}
flavorDimensions "products"
productFlavors {
editor {}
template {}
}
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']
dev.jniLibs.srcDirs = ['libs/dev']
release.jniLibs.srcDirs = ['libs/release']
// Editor jni library
editorRelease.jniLibs.srcDirs = ['libs/tools/release']
editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
editorDev.jniLibs.srcDirs = ['libs/tools/dev']
}
libraryVariants.all { variant ->
def flavorName = variant.getFlavorName()
if (flavorName == null || flavorName == "") {
throw new GradleException("Invalid product flavor: $flavorName")
}
boolean toolsFlag = flavorName == "editor"
def buildType = variant.buildType.name
if (buildType == null || buildType == "" || !supportedTargetsMapByFlavors[flavorName].containsKey(buildType)) {
throw new GradleException("Invalid build type: $buildType")
}
boolean productionBuild = buildType != "dev"
boolean storeRelease = buildType == "release"
def sconsTarget = supportedTargetsMapByFlavors[flavorName][buildType]
if (sconsTarget == null || sconsTarget == "") {
throw new GradleException("Invalid scons target: $sconsTarget")
}
// Update the name of the generated library
def outputSuffix = "${buildType}.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.debug("Looking for $sconsName executable path")
for (ext in sconsExts) {
String sconsNameExt = sconsName + ext
logger.debug("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.debug("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", "store_release=${storeRelease}", "production=${productionBuild}", "tools=${toolsFlag}", "target=${sconsTarget}", "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.capitalize()}JniLibFolders"].dependsOn taskName
}
}
publishing {
singleVariant("templateRelease") {
withSourcesJar()
withJavadocJar()
}
}
}