| 1 |
plugins { |
| 2 |
id 'io.github.gradle-nexus.publish-plugin' |
| 3 |
} |
| 4 |
|
| 5 |
apply from: 'app/config.gradle' |
| 6 |
apply from: 'scripts/publish-root.gradle' |
| 7 |
|
| 8 |
ext { |
| 9 |
PUBLISH_VERSION = getGodotPublishVersion() |
| 10 |
} |
| 11 |
|
| 12 |
group = ossrhGroupId |
| 13 |
version = PUBLISH_VERSION |
| 14 |
|
| 15 |
allprojects { |
| 16 |
repositories { |
| 17 |
google() |
| 18 |
mavenCentral() |
| 19 |
gradlePluginPortal() |
| 20 |
maven { url "https://plugins.gradle.org/m2/" } |
| 21 |
maven { url "https://central.sonatype.com/repository/maven-snapshots/"} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
ext { |
| 26 |
supportedAbis = ["arm32", "arm64", "x86_32", "x86_64"] |
| 27 |
supportedFlavors = ["editor", "template"] |
| 28 |
supportedAndroidDistributions = ["android", "horizonos", "picoos"] |
| 29 |
supportedFlavorsBuildTypes = [ |
| 30 |
"editor": ["dev", "debug", "release"], |
| 31 |
"template": ["dev", "debug", "release"] |
| 32 |
] |
| 33 |
supportedEditions = ["standard", "mono"] |
| 34 |
|
| 35 |
// Used by gradle to specify which architecture to build for by default when running |
| 36 |
// `./gradlew build` (this command is usually used by Android Studio). |
| 37 |
// If building manually on the command line, it's recommended to use the |
| 38 |
// `./gradlew generateGodotTemplates` build command instead after running the `scons` command(s). |
| 39 |
// The {selectedAbis} values must be from the {supportedAbis} values. |
| 40 |
selectedAbis = ["arm64"] |
| 41 |
|
| 42 |
rootDir = "../../.." |
| 43 |
binDir = "$rootDir/bin/" |
| 44 |
androidEditorBuildsDir = "$binDir/android_editor_builds/" |
| 45 |
} |
| 46 |
|
| 47 |
def getSconsTaskName(String flavor, String buildType, String abi) { |
| 48 |
return "compileGodotNativeLibs" + flavor.capitalize() + buildType.capitalize() + abi.capitalize() |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Generate Godot gradle build template by zipping the source files from the app directory, as well |
| 53 |
* as the AAR files generated by 'copyDebugAAR', 'copyDevAAR' and 'copyReleaseAAR'. |
| 54 |
* The zip file also includes some gradle tools to enable gradle builds from the Godot Editor. |
| 55 |
*/ |
| 56 |
task zipGradleBuild(type: Zip) { |
| 57 |
onlyIf { generateGodotTemplates.state.executed || generateGodotMonoTemplates.state.executed || generateDevTemplate.state.executed } |
| 58 |
doFirst { |
| 59 |
logger.lifecycle("Generating Godot gradle build template") |
| 60 |
} |
| 61 |
from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradlew', 'gradlew.bat', 'gradle/**'])) |
| 62 |
include '**/*' |
| 63 |
archiveFileName = 'android_source.zip' |
| 64 |
destinationDirectory = file(binDir) |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns true if the scons build tasks responsible for generating the Godot native shared |
| 69 |
* libraries should be excluded. |
| 70 |
*/ |
| 71 |
def excludeSconsBuildTasks() { |
| 72 |
return !isAndroidStudio() && !project.hasProperty("generateNativeLibs") |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Generates the list of build tasks that should be excluded from the build process.\ |
| 77 |
*/ |
| 78 |
def templateExcludedBuildTask() { |
| 79 |
// We exclude these gradle tasks so we can run the scons command manually. |
| 80 |
def excludedTasks = [] |
| 81 |
if (excludeSconsBuildTasks()) { |
| 82 |
logger.info("Excluding Android studio build tasks") |
| 83 |
for (String flavor : supportedFlavors) { |
| 84 |
String[] supportedBuildTypes = supportedFlavorsBuildTypes[flavor] |
| 85 |
for (String buildType : supportedBuildTypes) { |
| 86 |
for (String abi : selectedAbis) { |
| 87 |
excludedTasks += ":lib:" + getSconsTaskName(flavor, buildType, abi) |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
} |
| 92 |
return excludedTasks |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Generates the build tasks for the given flavor |
| 97 |
* @param flavor Must be one of the supported flavors ('template' / 'editor') |
| 98 |
* @param edition Must be one of the supported editions ('standard' / 'mono') |
| 99 |
* @param androidDistro Must be one of the supported Android distributions ('android' / 'horizonos' / 'picoos') |
| 100 |
*/ |
| 101 |
def generateBuildTasks(String flavor = "template", String edition = "standard", String androidDistro = "android") { |
| 102 |
if (!supportedFlavors.contains(flavor)) { |
| 103 |
throw new GradleException("Invalid build flavor: $flavor") |
| 104 |
} |
| 105 |
if (!supportedAndroidDistributions.contains(androidDistro)) { |
| 106 |
throw new GradleException("Invalid Android distribution: $androidDistro") |
| 107 |
} |
| 108 |
if (!supportedEditions.contains(edition)) { |
| 109 |
throw new GradleException("Invalid build edition: $edition") |
| 110 |
} |
| 111 |
if (edition == "mono" && flavor != "template") { |
| 112 |
throw new GradleException("'mono' edition only supports the 'template' flavor.") |
| 113 |
} |
| 114 |
|
| 115 |
String capitalizedAndroidDistro = androidDistro.capitalize() |
| 116 |
def buildTasks = [] |
| 117 |
|
| 118 |
// Only build the binary files for which we have native shared libraries unless we intend |
| 119 |
// to run the scons build tasks. |
| 120 |
boolean excludeSconsBuildTasks = excludeSconsBuildTasks() |
| 121 |
boolean isTemplate = flavor == "template" |
| 122 |
String libsDir = isTemplate ? "lib/libs/" : "lib/libs/tools/" |
| 123 |
for (String target : supportedFlavorsBuildTypes[flavor]) { |
| 124 |
File targetLibs = new File(libsDir + target) |
| 125 |
|
| 126 |
String targetSuffix = target |
| 127 |
if (target == "dev") { |
| 128 |
targetSuffix = "debug.dev" |
| 129 |
} |
| 130 |
|
| 131 |
if (!excludeSconsBuildTasks || (targetLibs != null |
| 132 |
&& targetLibs.isDirectory() |
| 133 |
&& targetLibs.listFiles() != null |
| 134 |
&& targetLibs.listFiles().length > 0)) { |
| 135 |
|
| 136 |
String capitalizedTarget = target.capitalize() |
| 137 |
String capitalizedEdition = edition.capitalize() |
| 138 |
if (isTemplate) { |
| 139 |
// Copy the Godot android library archive file into the app module libs directory. |
| 140 |
// Depends on the library build task to ensure the AAR file is generated prior to copying. |
| 141 |
String copyAARTaskName = "copy${capitalizedTarget}AARToAppModule" |
| 142 |
if (tasks.findByName(copyAARTaskName) != null) { |
| 143 |
buildTasks += tasks.getByName(copyAARTaskName) |
| 144 |
} else { |
| 145 |
buildTasks += tasks.create(name: copyAARTaskName, type: Copy) { |
| 146 |
dependsOn ":lib:assembleTemplate${capitalizedTarget}" |
| 147 |
from('lib/build/outputs/aar') |
| 148 |
include("godot-lib.template_${targetSuffix}.aar") |
| 149 |
into("app/libs/${target}") |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
// Copy the Godot android library archive file into the root bin directory. |
| 154 |
// Depends on the library build task to ensure the AAR file is generated prior to copying. |
| 155 |
String copyAARToBinTaskName = "copy${capitalizedTarget}AARToBin" |
| 156 |
if (tasks.findByName(copyAARToBinTaskName) != null) { |
| 157 |
buildTasks += tasks.getByName(copyAARToBinTaskName) |
| 158 |
} else { |
| 159 |
buildTasks += tasks.create(name: copyAARToBinTaskName, type: Copy) { |
| 160 |
dependsOn ":lib:assembleTemplate${capitalizedTarget}" |
| 161 |
from('lib/build/outputs/aar') |
| 162 |
include("godot-lib.template_${targetSuffix}.aar") |
| 163 |
into(binDir) |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
// Copy the generated binary template into the Godot bin directory. |
| 168 |
// Depends on the app build task to ensure the binary is generated prior to copying. |
| 169 |
String copyBinaryTaskName = "copy${capitalizedEdition}${capitalizedTarget}BinaryToBin" |
| 170 |
if (tasks.findByName(copyBinaryTaskName) != null) { |
| 171 |
buildTasks += tasks.getByName(copyBinaryTaskName) |
| 172 |
} else { |
| 173 |
buildTasks += tasks.create(name: copyBinaryTaskName, type: Copy) { |
| 174 |
String filenameSuffix = edition == "mono" ? "${edition}${capitalizedTarget}" : target |
| 175 |
dependsOn ":app:assemble${capitalizedEdition}${capitalizedTarget}" |
| 176 |
from("app/build/outputs/apk/${edition}/${target}") { |
| 177 |
include("android_${filenameSuffix}.apk") |
| 178 |
} |
| 179 |
into(binDir) |
| 180 |
} |
| 181 |
} |
| 182 |
} else { |
| 183 |
// Copy the generated editor apk to the bin directory. |
| 184 |
String copyEditorApkTaskName = "copyEditor${capitalizedAndroidDistro}${capitalizedTarget}ApkToBin" |
| 185 |
if (tasks.findByName(copyEditorApkTaskName) != null) { |
| 186 |
buildTasks += tasks.getByName(copyEditorApkTaskName) |
| 187 |
} else { |
| 188 |
buildTasks += tasks.create(name: copyEditorApkTaskName, type: Copy) { |
| 189 |
dependsOn ":editor:assemble${capitalizedAndroidDistro}${capitalizedTarget}" |
| 190 |
from("editor/build/outputs/apk/${androidDistro}/${target}") { |
| 191 |
include("android_editor-${androidDistro}-${target}*.apk") |
| 192 |
} |
| 193 |
into(androidEditorBuildsDir) |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
// Copy the generated editor aab to the bin directory. |
| 198 |
String copyEditorAabTaskName = "copyEditor${capitalizedAndroidDistro}${capitalizedTarget}AabToBin" |
| 199 |
if (tasks.findByName(copyEditorAabTaskName) != null) { |
| 200 |
buildTasks += tasks.getByName(copyEditorAabTaskName) |
| 201 |
} else { |
| 202 |
buildTasks += tasks.create(name: copyEditorAabTaskName, type: Copy) { |
| 203 |
dependsOn ":editor:bundle${capitalizedAndroidDistro}${capitalizedTarget}" |
| 204 |
from("editor/build/outputs/bundle/${androidDistro}${capitalizedTarget}") |
| 205 |
into(androidEditorBuildsDir) |
| 206 |
include("android_editor-${androidDistro}-${target}*.aab") |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} else { |
| 211 |
logger.info("No native shared libs for target $target. Skipping build.") |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
return buildTasks |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Generate the Godot Editor binaries for Android devices. |
| 220 |
* |
| 221 |
* Note: Unless the 'generateNativeLibs` argument is specified, the Godot 'tools' shared libraries |
| 222 |
* must have been generated (via scons) prior to running this gradle task. |
| 223 |
* The task will only build the binaries for which the shared libraries is available. |
| 224 |
*/ |
| 225 |
task generateGodotEditor { |
| 226 |
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() |
| 227 |
dependsOn = generateBuildTasks("editor", "standard", "android") |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Generate the Godot Editor binaries for HorizonOS devices. |
| 232 |
* |
| 233 |
* Note: Unless the 'generateNativeLibs` argument is specified, the Godot 'tools' shared libraries |
| 234 |
* must have been generated (via scons) prior to running this gradle task. |
| 235 |
* The task will only build the binaries for which the shared libraries is available. |
| 236 |
*/ |
| 237 |
task generateGodotHorizonOSEditor { |
| 238 |
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() |
| 239 |
dependsOn = generateBuildTasks("editor", "standard", "horizonos") |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Generate the Godot Editor binaries for PicoOS devices. |
| 244 |
* |
| 245 |
* Note: Unless the 'generateNativeLibs` argument is specified, the Godot 'tools' shared libraries |
| 246 |
* must have been generated (via scons) prior to running this gradle task. |
| 247 |
* The task will only build the binaries for which the shared libraries is available. |
| 248 |
*/ |
| 249 |
task generateGodotPicoOSEditor { |
| 250 |
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() |
| 251 |
dependsOn = generateBuildTasks("editor", "standard", "picoos") |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* Master task used to coordinate the tasks defined above to generate the set of Godot templates. |
| 256 |
*/ |
| 257 |
task generateGodotTemplates { |
| 258 |
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() |
| 259 |
dependsOn = generateBuildTasks("template") |
| 260 |
|
| 261 |
finalizedBy 'zipGradleBuild' |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Master task used to coordinate the tasks defined above to generate the set of Godot templates |
| 266 |
* for the 'mono' edition of the engine. |
| 267 |
*/ |
| 268 |
task generateGodotMonoTemplates { |
| 269 |
gradle.startParameter.excludedTaskNames += templateExcludedBuildTask() |
| 270 |
dependsOn = generateBuildTasks("template", "mono") |
| 271 |
|
| 272 |
finalizedBy 'zipGradleBuild' |
| 273 |
} |
| 274 |
|
| 275 |
task clean(type: Delete) { |
| 276 |
dependsOn 'cleanGodotEditor' |
| 277 |
dependsOn 'cleanGodotTemplates' |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Clean the generated editor artifacts. |
| 282 |
*/ |
| 283 |
task cleanGodotEditor(type: Delete) { |
| 284 |
// Delete the generated native tools libs |
| 285 |
delete("lib/libs/tools") |
| 286 |
|
| 287 |
// Delete the library generated AAR files |
| 288 |
delete("lib/build/outputs/aar") |
| 289 |
|
| 290 |
// Delete the generated binary apks |
| 291 |
delete("editor/build/outputs/apk") |
| 292 |
|
| 293 |
// Delete the generated aab binaries |
| 294 |
delete("editor/build/outputs/bundle") |
| 295 |
|
| 296 |
// Delete the Godot editor apks & aabs in the Godot bin directory |
| 297 |
delete(androidEditorBuildsDir) |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Clean the generated template artifacts. |
| 302 |
*/ |
| 303 |
task cleanGodotTemplates(type: Delete) { |
| 304 |
// Delete the generated native libs |
| 305 |
delete("lib/libs") |
| 306 |
|
| 307 |
// Delete the library generated AAR files |
| 308 |
delete("lib/build/outputs/aar") |
| 309 |
|
| 310 |
// Delete the app libs directory contents |
| 311 |
delete("app/libs") |
| 312 |
|
| 313 |
// Delete the generated binary apks |
| 314 |
delete("app/build/outputs/apk") |
| 315 |
|
| 316 |
// Delete the Godot templates in the Godot bin directory |
| 317 |
delete("$binDir/android_debug.apk") |
| 318 |
delete("$binDir/android_dev.apk") |
| 319 |
delete("$binDir/android_release.apk") |
| 320 |
delete("$binDir/android_monoDebug.apk") |
| 321 |
delete("$binDir/android_monoDev.apk") |
| 322 |
delete("$binDir/android_monoRelease.apk") |
| 323 |
delete("$binDir/android_source.zip") |
| 324 |
delete("$binDir/godot-lib.template_debug.aar") |
| 325 |
delete("$binDir/godot-lib.template_debug.dev.aar") |
| 326 |
delete("$binDir/godot-lib.template_release.aar") |
| 327 |
|
| 328 |
// Cover deletion for the libs using the previous naming scheme |
| 329 |
delete("$binDir/godot-lib.debug.aar") |
| 330 |
delete("$binDir/godot-lib.dev.aar") |
| 331 |
delete("$binDir/godot-lib.release.aar") |
| 332 |
|
| 333 |
// Delete the native debug symbols files. |
| 334 |
delete("$binDir/android-editor-debug-native-symbols.zip") |
| 335 |
delete("$binDir/android-editor-dev-native-symbols.zip") |
| 336 |
delete("$binDir/android-editor-release-native-symbols.zip") |
| 337 |
delete("$binDir/android-template-debug-native-symbols.zip") |
| 338 |
delete("$binDir/android-template-dev-native-symbols.zip") |
| 339 |
delete("$binDir/android-template-release-native-symbols.zip") |
| 340 |
} |