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