| 1 |
plugins { |
| 2 |
id 'com.android.library' |
| 3 |
id 'org.jetbrains.kotlin.android' |
| 4 |
} |
| 5 |
|
| 6 |
ext { |
| 7 |
DEBUG_PUBLISH_ARTIFACT_ID = 'godot-debug' |
| 8 |
PUBLISH_ARTIFACT_ID = 'godot' |
| 9 |
TOOLS_PUBLISH_ARTIFACT_ID = 'godot-tools' |
| 10 |
} |
| 11 |
|
| 12 |
apply from: "../scripts/publish-module.gradle" |
| 13 |
|
| 14 |
dependencies { |
| 15 |
implementation "androidx.fragment:fragment:$versions.fragmentVersion" |
| 16 |
implementation "androidx.documentfile:documentfile:$versions.documentfileVersion" |
| 17 |
|
| 18 |
testImplementation "junit:junit:4.13.2" |
| 19 |
} |
| 20 |
|
| 21 |
def pathToRootDir = "../../../../" |
| 22 |
|
| 23 |
android { |
| 24 |
compileSdkVersion versions.compileSdk |
| 25 |
buildToolsVersion versions.buildTools |
| 26 |
ndkVersion versions.ndkVersion |
| 27 |
|
| 28 |
defaultConfig { |
| 29 |
minSdkVersion versions.minSdk |
| 30 |
targetSdkVersion versions.targetSdk |
| 31 |
|
| 32 |
manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()] |
| 33 |
} |
| 34 |
|
| 35 |
namespace = "org.godotengine.godot" |
| 36 |
|
| 37 |
compileOptions { |
| 38 |
sourceCompatibility versions.javaVersion |
| 39 |
targetCompatibility versions.javaVersion |
| 40 |
} |
| 41 |
|
| 42 |
kotlinOptions { |
| 43 |
jvmTarget = versions.javaVersion |
| 44 |
} |
| 45 |
|
| 46 |
buildFeatures { |
| 47 |
aidl = true |
| 48 |
buildConfig = true |
| 49 |
} |
| 50 |
|
| 51 |
buildTypes { |
| 52 |
dev { |
| 53 |
initWith debug |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
flavorDimensions = ["products"] |
| 58 |
productFlavors { |
| 59 |
editor {} |
| 60 |
template {} |
| 61 |
} |
| 62 |
|
| 63 |
lintOptions { |
| 64 |
abortOnError false |
| 65 |
disable 'MissingTranslation', 'UnusedResources' |
| 66 |
} |
| 67 |
|
| 68 |
packagingOptions { |
| 69 |
exclude 'META-INF/LICENSE' |
| 70 |
exclude 'META-INF/NOTICE' |
| 71 |
|
| 72 |
// Debug symbols are kept for development within Android Studio. |
| 73 |
if (shouldNotStrip()) { |
| 74 |
jniLibs { |
| 75 |
keepDebugSymbols += '**/*.so' |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
sourceSets { |
| 81 |
debug.jniLibs.srcDirs = ['libs/debug'] |
| 82 |
dev.jniLibs.srcDirs = ['libs/dev'] |
| 83 |
release.jniLibs.srcDirs = ['libs/release'] |
| 84 |
|
| 85 |
// Editor jni library |
| 86 |
editorRelease.jniLibs.srcDirs = ['libs/tools/release'] |
| 87 |
editorDebug.jniLibs.srcDirs = ['libs/tools/debug'] |
| 88 |
editorDev.jniLibs.srcDirs = ['libs/tools/dev'] |
| 89 |
} |
| 90 |
|
| 91 |
libraryVariants.all { variant -> |
| 92 |
def flavorName = variant.getFlavorName() |
| 93 |
if (flavorName == null || flavorName == "") { |
| 94 |
throw new GradleException("Invalid product flavor: $flavorName") |
| 95 |
} |
| 96 |
|
| 97 |
def buildType = variant.buildType.name |
| 98 |
if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) { |
| 99 |
throw new GradleException("Invalid build type: $buildType") |
| 100 |
} |
| 101 |
|
| 102 |
boolean devBuild = buildType == "dev" |
| 103 |
boolean debugSymbols = devBuild |
| 104 |
boolean runTests = devBuild |
| 105 |
boolean storeRelease = buildType == "release" |
| 106 |
boolean productionBuild = storeRelease |
| 107 |
|
| 108 |
def sconsTarget = flavorName |
| 109 |
if (sconsTarget == "template") { |
| 110 |
// Tests are not supported on template builds |
| 111 |
runTests = false |
| 112 |
switch (buildType) { |
| 113 |
case "release": |
| 114 |
sconsTarget += "_release" |
| 115 |
break |
| 116 |
case "debug": |
| 117 |
case "dev": |
| 118 |
default: |
| 119 |
sconsTarget += "_debug" |
| 120 |
break |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
// Update the name of the generated library |
| 125 |
def outputSuffix = "${sconsTarget}" |
| 126 |
if (devBuild) { |
| 127 |
outputSuffix = "${outputSuffix}.dev" |
| 128 |
} |
| 129 |
variant.outputs.all { output -> |
| 130 |
output.outputFileName = "godot-lib.${outputSuffix}.aar" |
| 131 |
} |
| 132 |
|
| 133 |
// Find scons' executable path |
| 134 |
File sconsExecutableFile = null |
| 135 |
def sconsName = "scons" |
| 136 |
def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows() |
| 137 |
? [".bat", ".cmd", ".ps1", ".exe"] |
| 138 |
: [""]) |
| 139 |
logger.debug("Looking for $sconsName executable path") |
| 140 |
for (ext in sconsExts) { |
| 141 |
String sconsNameExt = sconsName + ext |
| 142 |
logger.debug("Checking $sconsNameExt") |
| 143 |
sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt) |
| 144 |
if (sconsExecutableFile != null) { |
| 145 |
// We're done! |
| 146 |
break |
| 147 |
} |
| 148 |
// Check all the options in path |
| 149 |
List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt) |
| 150 |
if (!allOptions.isEmpty()) { |
| 151 |
// Pick the first option and we're done! |
| 152 |
sconsExecutableFile = allOptions.get(0) |
| 153 |
break |
| 154 |
} |
| 155 |
} |
| 156 |
if (sconsExecutableFile == null) { |
| 157 |
throw new GradleException("Unable to find executable path for the '$sconsName' command.") |
| 158 |
} else { |
| 159 |
logger.debug("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}") |
| 160 |
} |
| 161 |
|
| 162 |
for (String selectedAbi : selectedAbis) { |
| 163 |
if (!supportedAbis.contains(selectedAbi)) { |
| 164 |
throw new GradleException("Invalid selected abi: $selectedAbi") |
| 165 |
} |
| 166 |
|
| 167 |
// Creating gradle task to generate the native libraries for the selected abi. |
| 168 |
def taskName = getSconsTaskName(flavorName, buildType, selectedAbi) |
| 169 |
tasks.create(name: taskName, type: Exec) { |
| 170 |
executable sconsExecutableFile.absolutePath |
| 171 |
args "--directory=${pathToRootDir}", "platform=android", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${devBuild}", "dev_build=${devBuild}", "debug_symbols=${debugSymbols}", "tests=${runTests}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors() |
| 172 |
} |
| 173 |
|
| 174 |
// Schedule the tasks so the generated libs are present before the aar file is packaged. |
| 175 |
tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
publishing { |
| 180 |
singleVariant("templateDebug") { |
| 181 |
withSourcesJar() |
| 182 |
withJavadocJar() |
| 183 |
} |
| 184 |
singleVariant("templateRelease") { |
| 185 |
withSourcesJar() |
| 186 |
withJavadocJar() |
| 187 |
} |
| 188 |
singleVariant("editorRelease") { |
| 189 |
withSourcesJar() |
| 190 |
withJavadocJar() |
| 191 |
} |
| 192 |
} |
| 193 |
} |