Debian Codegraph @

platform/android/java/app/config.gradle

raw
1 ext.versions = [
2 androidGradlePlugin: '8.6.1',
3 compileSdk : 36,
4 // Also update:
5 // - 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
6 // - 'platform/android/detect.py#get_min_target_api()'
7 minSdk : 24,
8 // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
9 targetSdk : 36,
10 buildTools : '36.1.0',
11 kotlinVersion : '2.1.21',
12 fragmentVersion : '1.8.6',
13 nexusPublishVersion: '1.3.0',
14 javaVersion : JavaVersion.VERSION_17,
15 // Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
16 ndkVersion : '29.0.14206865',
17 splashscreenVersion: '1.0.1',
18 // 'openxrLoaderVersion' should be set to XR_CURRENT_API_VERSION, see 'thirdparty/openxr'
19 openxrLoaderVersion: '1.1.53',
20 openxrVendorsVersion: '4.3.0-stable',
21 junitVersion : '1.3.0',
22 espressoCoreVersion: '3.7.0',
23 kotlinTestVersion : '1.3.11',
24 testRunnerVersion : '1.7.0',
25 testOrchestratorVersion: '1.6.1',
26 documentfileVersion: '1.1.0',
27 ]
28
29 ext.getExportPackageName = { ->
30 // Retrieve the app id from the project property set by the Godot build command.
31 String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
32 // Check if the app id is valid, otherwise use the default.
33 if (appId == null || appId.isEmpty()) {
34 appId = "com.godot.game"
35 }
36 return appId
37 }
38
39 ext.getExportVersionCode = { ->
40 String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
41 if (versionCode == null || versionCode.isEmpty()) {
42 versionCode = "1"
43 }
44 try {
45 return Integer.parseInt(versionCode)
46 } catch (NumberFormatException ignored) {
47 return 1
48 }
49 }
50
51 ext.getExportVersionName = { ->
52 String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
53 if (versionName == null || versionName.isEmpty()) {
54 versionName = "1.0"
55 }
56 return versionName
57 }
58
59 ext.getExportMinSdkVersion = { ->
60 String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
61 if (minSdkVersion == null || minSdkVersion.isEmpty()) {
62 minSdkVersion = "$versions.minSdk"
63 }
64 try {
65 return Integer.parseInt(minSdkVersion)
66 } catch (NumberFormatException ignored) {
67 return versions.minSdk
68 }
69 }
70
71 ext.getExportTargetSdkVersion = { ->
72 String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
73 if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
74 targetSdkVersion = "$versions.targetSdk"
75 }
76 try {
77 return Integer.parseInt(targetSdkVersion)
78 } catch (NumberFormatException ignored) {
79 return versions.targetSdk
80 }
81 }
82
83 ext.getGodotLibraryVersionCode = { ->
84 String versionName = ""
85 int versionCode = 1
86 (versionName, versionCode) = getGodotLibraryVersion()
87 return versionCode
88 }
89
90 ext.getGodotLibraryVersionName = { ->
91 String versionName = ""
92 int versionCode = 1
93 (versionName, versionCode) = getGodotLibraryVersion()
94 return versionName
95 }
96
97 ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
98 // Attempt to read the version from the `version.py` file.
99 String libraryVersionName = ""
100 int libraryVersionCode = 0
101
102 File versionFile = new File("../../../version.py")
103 if (versionFile.isFile()) {
104 def map = [:]
105
106 List<String> lines = versionFile.readLines()
107 for (String line in lines) {
108 String[] keyValue = line.split("=")
109 String key = keyValue[0].trim()
110 String value = keyValue[1].trim().replaceAll("\"", "")
111
112 if (requiredKeys.contains(key)) {
113 if (!value.isEmpty()) {
114 map[key] = value
115 }
116 requiredKeys.remove(key)
117 }
118 }
119
120 if (requiredKeys.empty) {
121 libraryVersionName = map.values().join(".")
122 try {
123 if (map.containsKey("status")) {
124 int statusCode = 0
125 String statusValue = map["status"]
126 if (statusValue == null) {
127 statusCode = 0
128 } else if (statusValue.startsWith("dev")) {
129 statusCode = 1
130 } else if (statusValue.startsWith("alpha")) {
131 statusCode = 2
132 } else if (statusValue.startsWith("beta")) {
133 statusCode = 3
134 } else if (statusValue.startsWith("rc")) {
135 statusCode = 4
136 } else if (statusValue.startsWith("stable")) {
137 statusCode = 5
138 } else {
139 statusCode = 0
140 }
141
142 libraryVersionCode = statusCode
143 }
144
145 if (map.containsKey("patch")) {
146 libraryVersionCode += Integer.parseInt(map["patch"]) * 10
147 }
148
149 if (map.containsKey("minor")) {
150 libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
151 }
152
153 if (map.containsKey("major")) {
154 libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
155 }
156 } catch (NumberFormatException ignore) {
157 libraryVersionCode = 1
158 }
159 }
160 }
161
162 if (libraryVersionName.isEmpty()) {
163 // Fallback value in case we're unable to read the file.
164 libraryVersionName = "custom_build"
165 }
166
167 if (libraryVersionCode == 0) {
168 libraryVersionCode = 1
169 }
170
171 return [libraryVersionName, libraryVersionCode]
172 }
173
174 ext.getGodotLibraryVersion = { ->
175 List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
176 return generateGodotLibraryVersion(requiredKeys)
177 }
178
179 ext.getGodotPublishVersion = { ->
180 List<String> requiredKeys = ["major", "minor", "patch", "status"]
181 String versionName = ""
182 int versionCode = 1
183 (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
184 if (!versionName.endsWith("stable")) {
185 versionName += "-SNAPSHOT"
186 }
187 return versionName
188 }
189
190 final String VALUE_SEPARATOR_REGEX = "\\|"
191
192 // get the list of ABIs the project should be exported to
193 ext.getExportEnabledABIs = { ->
194 String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : ""
195 if (enabledABIs == null || enabledABIs.isEmpty()) {
196 enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
197 }
198 Set<String> exportAbiFilter = []
199 for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
200 if (!abi_name.trim().isEmpty()){
201 exportAbiFilter.add(abi_name)
202 }
203 }
204 return exportAbiFilter
205 }
206
207 ext.getExportPath = {
208 String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
209 if (exportPath == null || exportPath.isEmpty()) {
210 exportPath = "."
211 }
212 return exportPath
213 }
214
215 ext.getExportFilename = {
216 String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
217 if (exportFilename == null || exportFilename.isEmpty()) {
218 exportFilename = "godot_android"
219 }
220 return exportFilename
221 }
222
223 ext.getExportEdition = {
224 String exportEdition = project.hasProperty("export_edition") ? project.property("export_edition") : ""
225 if (exportEdition == null || exportEdition.isEmpty()) {
226 exportEdition = "standard"
227 }
228 return exportEdition
229 }
230
231 ext.getExportBuildType = {
232 String exportBuildType = project.hasProperty("export_build_type") ? project.property("export_build_type") : ""
233 if (exportBuildType == null || exportBuildType.isEmpty()) {
234 exportBuildType = "debug"
235 }
236 return exportBuildType
237 }
238
239 ext.getExportFormat = {
240 String exportFormat = project.hasProperty("export_format") ? project.property("export_format") : ""
241 if (exportFormat == null || exportFormat.isEmpty()) {
242 exportFormat = "apk"
243 }
244 return exportFormat
245 }
246
247 /**
248 * Parse the project properties for the 'plugins_maven_repos' property and return the list
249 * of maven repos.
250 */
251 ext.getGodotPluginsMavenRepos = { ->
252 Set<String> mavenRepos = []
253
254 // Retrieve the list of maven repos.
255 if (project.hasProperty("plugins_maven_repos")) {
256 String mavenReposProperty = project.property("plugins_maven_repos")
257 if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
258 for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
259 mavenRepos += mavenRepoUrl.trim()
260 }
261 }
262 }
263
264 return mavenRepos
265 }
266
267 /**
268 * Parse the project properties for the 'plugins_remote_binaries' property and return
269 * it for inclusion in the build dependencies.
270 */
271 ext.getGodotPluginsRemoteBinaries = { ->
272 Set<String> remoteDeps = []
273
274 // Retrieve the list of remote plugins binaries.
275 if (project.hasProperty("plugins_remote_binaries")) {
276 String remoteDepsList = project.property("plugins_remote_binaries")
277 if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
278 for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
279 remoteDeps += dep.trim()
280 }
281 }
282 }
283 return remoteDeps
284 }
285
286 /**
287 * Parse the project properties for the 'plugins_local_binaries' property and return
288 * their binaries for inclusion in the build dependencies.
289 */
290 ext.getGodotPluginsLocalBinaries = { ->
291 Set<String> binDeps = []
292
293 // Retrieve the list of local plugins binaries.
294 if (project.hasProperty("plugins_local_binaries")) {
295 String pluginsList = project.property("plugins_local_binaries")
296 if (pluginsList != null && !pluginsList.trim().isEmpty()) {
297 for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
298 binDeps += plugin.trim()
299 }
300 }
301 }
302
303 return binDeps
304 }
305
306 ext.getDebugKeystoreFile = { ->
307 String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
308 if (keystoreFile == null || keystoreFile.isEmpty()) {
309 keystoreFile = "."
310 }
311 return keystoreFile
312 }
313
314 ext.hasCustomDebugKeystore = { ->
315 File keystoreFile = new File(getDebugKeystoreFile())
316 return keystoreFile.isFile()
317 }
318
319 ext.getDebugKeystorePassword = { ->
320 String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
321 if (keystorePassword == null || keystorePassword.isEmpty()) {
322 keystorePassword = "android"
323 }
324 return keystorePassword
325 }
326
327 ext.getDebugKeyAlias = { ->
328 String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
329 if (keyAlias == null || keyAlias.isEmpty()) {
330 keyAlias = "androiddebugkey"
331 }
332 return keyAlias
333 }
334
335 ext.getReleaseKeystoreFile = { ->
336 String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
337 if (keystoreFile == null || keystoreFile.isEmpty()) {
338 keystoreFile = "."
339 }
340 return keystoreFile
341 }
342
343 ext.getReleaseKeystorePassword = { ->
344 String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
345 return keystorePassword
346 }
347
348 ext.getReleaseKeyAlias = { ->
349 String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
350 return keyAlias
351 }
352
353 ext.isAndroidStudio = { ->
354 return project.hasProperty('android.injected.invoked.from.ide')
355 }
356
357 ext.shouldZipAlign = { ->
358 String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
359 if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
360 if (isAndroidStudio()) {
361 zipAlignFlag = "true"
362 } else {
363 zipAlignFlag = "false"
364 }
365 }
366 return Boolean.parseBoolean(zipAlignFlag)
367 }
368
369 ext.shouldSign = { ->
370 String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
371 if (signFlag == null || signFlag.isEmpty()) {
372 if (isAndroidStudio()) {
373 signFlag = "true"
374 } else {
375 signFlag = "false"
376 }
377 }
378 return Boolean.parseBoolean(signFlag)
379 }
380
381 ext.shouldNotStrip = { ->
382 return isAndroidStudio() || project.hasProperty("doNotStrip")
383 }
384
385 /**
386 * Whether to use the legacy convention of compressing all .so files in the APK.
387 *
388 * For more background, see:
389 * - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
390 * - https://stackoverflow.com/a/44704840
391 */
392 ext.shouldUseLegacyPackaging = { ->
393 String legacyPackagingFlag = project.hasProperty("compress_native_libraries") ? project.property("compress_native_libraries") : ""
394 if (legacyPackagingFlag != null && !legacyPackagingFlag.isEmpty()) {
395 return Boolean.parseBoolean(legacyPackagingFlag)
396 }
397
398 if (getExportMinSdkVersion() <= 29) {
399 // Use legacy packaging for compatibility with device running api <= 29.
400 // See https://github.com/godotengine/godot/issues/108842 for reference.
401 return true
402 }
403
404 // Default behavior for minSdk > 29.
405 return false
406 }
407
408 ext.getAddonsDirectory = { ->
409 String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : ""
410 return addonsDirectory
411 }