summaryrefslogtreecommitdiff
path: root/platform/android/java/app/config.gradle
blob: 95f46bbb7b4de818d6308754532fcaf4e86db579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
ext.versions = [
    androidGradlePlugin: '7.2.1',
    compileSdk         : 32,
    // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
    minSdk             : 21,
    // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
    targetSdk          : 32,
    buildTools         : '32.0.0',
    kotlinVersion      : '1.7.0',
    fragmentVersion    : '1.3.6',
    nexusPublishVersion: '1.1.0',
    javaVersion        : 11,
    // Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
    ndkVersion         : '23.2.8568313'

]

ext.libraries = [
    androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
    kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
    kotlinStdLib       : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlinVersion",
    androidxFragment   : "androidx.fragment:fragment:$versions.fragmentVersion",
]

ext.getExportPackageName = { ->
    // Retrieve the app id from the project property set by the Godot build command.
    String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
    // Check if the app id is valid, otherwise use the default.
    if (appId == null || appId.isEmpty()) {
        appId = "com.godot.game"
    }
    return appId
}

ext.getExportVersionCode = { ->
    String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
    if (versionCode == null || versionCode.isEmpty()) {
        versionCode = "1"
    }
    try {
        return Integer.parseInt(versionCode)
    } catch (NumberFormatException ignored) {
        return 1
    }
}

ext.getExportVersionName = { ->
    String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
    if (versionName == null || versionName.isEmpty()) {
        versionName = "1.0"
    }
    return versionName
}

ext.getExportMinSdkVersion = { ->
    String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
    if (minSdkVersion == null || minSdkVersion.isEmpty()) {
        minSdkVersion = "$versions.minSdk"
    }
    try {
        return Integer.parseInt(minSdkVersion)
    } catch (NumberFormatException ignored) {
        return versions.minSdk
    }
}

ext.getExportTargetSdkVersion = { ->
    String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
    if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
        targetSdkVersion = "$versions.targetSdk"
    }
    try {
        return Integer.parseInt(targetSdkVersion)
    } catch (NumberFormatException ignored) {
        return versions.targetSdk
    }
}

ext.getGodotEditorVersion = { ->
    String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
    if (editorVersion == null || editorVersion.isEmpty()) {
        // Try the library version first
        editorVersion = getGodotLibraryVersionName()

        if (editorVersion.isEmpty()) {
            // Fallback value.
            editorVersion = "custom_build"
        }
    }
    return editorVersion
}

ext.getGodotLibraryVersionCode = { ->
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = getGodotLibraryVersion()
    return versionCode
}

ext.getGodotLibraryVersionName = { ->
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = getGodotLibraryVersion()
    return versionName
}

ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
    // Attempt to read the version from the `version.py` file.
    String libraryVersionName = ""
    int libraryVersionCode = 0

    File versionFile = new File("../../../version.py")
    if (versionFile.isFile()) {
        def map = [:]

        List<String> lines = versionFile.readLines()
        for (String line in lines) {
            String[] keyValue = line.split("=")
            String key = keyValue[0].trim()
            String value = keyValue[1].trim().replaceAll("\"", "")

            if (requiredKeys.contains(key)) {
                if (!value.isEmpty()) {
                    map[key] = value
                }
                requiredKeys.remove(key)
            }
        }

        if (requiredKeys.empty) {
            libraryVersionName = map.values().join(".")
            try {
                if (map.containsKey("status")) {
                    int statusCode = 0
                    String statusValue = map["status"]
                    if (statusValue == null) {
                        statusCode = 0
                    } else if (statusValue.startsWith("alpha")) {
                        statusCode = 1
                    } else if (statusValue.startsWith("beta")) {
                        statusCode = 2
                    } else if (statusValue.startsWith("rc")) {
                        statusCode = 3
                    } else if (statusValue.startsWith("stable")) {
                        statusCode = 4
                    } else {
                        statusCode = 0
                    }

                    libraryVersionCode = statusCode
                }

                if (map.containsKey("patch")) {
                    libraryVersionCode += Integer.parseInt(map["patch"]) * 10
                }

                if (map.containsKey("minor")) {
                    libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
                }

                if (map.containsKey("major")) {
                    libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
                }
            } catch (NumberFormatException ignore) {
                libraryVersionCode = 1
            }
        }
    }

    if (libraryVersionName.isEmpty()) {
        // Fallback value in case we're unable to read the file.
        libraryVersionName = "custom_build"
    }

    if (libraryVersionCode == 0) {
        libraryVersionCode = 1
    }

    return [libraryVersionName, libraryVersionCode]
}

ext.getGodotLibraryVersion = { ->
    List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
    return generateGodotLibraryVersion(requiredKeys)
}

ext.getGodotPublishVersion = { ->
    List<String> requiredKeys = ["major", "minor", "patch", "status"]
    String versionName = ""
    int versionCode = 1
    (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
    if (!versionName.endsWith("stable")) {
        versionName += "-SNAPSHOT"
    }
    return versionName
}

final String VALUE_SEPARATOR_REGEX = "\\|"

// get the list of ABIs the project should be exported to
ext.getExportEnabledABIs = { ->
    String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
    if (enabledABIs == null || enabledABIs.isEmpty()) {
        enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
    }
    Set<String> exportAbiFilter = [];
    for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
        if (!abi_name.trim().isEmpty()){
            exportAbiFilter.add(abi_name);
        }
    }
    return exportAbiFilter;
}

ext.getExportPath = {
    String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
    if (exportPath == null || exportPath.isEmpty()) {
        exportPath = "."
    }
    return exportPath
}

ext.getExportFilename = {
    String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
    if (exportFilename == null || exportFilename.isEmpty()) {
        exportFilename = "godot_android"
    }
    return exportFilename
}

/**
 * Parse the project properties for the 'plugins_maven_repos' property and return the list
 * of maven repos.
 */
ext.getGodotPluginsMavenRepos = { ->
    Set<String> mavenRepos = []

    // Retrieve the list of maven repos.
    if (project.hasProperty("plugins_maven_repos")) {
        String mavenReposProperty = project.property("plugins_maven_repos")
        if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
            for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
                mavenRepos += mavenRepoUrl.trim()
            }
        }
    }

    return mavenRepos
}

/**
 * Parse the project properties for the 'plugins_remote_binaries' property and return
 * it for inclusion in the build dependencies.
 */
ext.getGodotPluginsRemoteBinaries = { ->
    Set<String> remoteDeps = []

    // Retrieve the list of remote plugins binaries.
    if (project.hasProperty("plugins_remote_binaries")) {
        String remoteDepsList = project.property("plugins_remote_binaries")
        if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
            for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
                remoteDeps += dep.trim()
            }
        }
    }
    return remoteDeps
}

/**
 * Parse the project properties for the 'plugins_local_binaries' property and return
 * their binaries for inclusion in the build dependencies.
 */
ext.getGodotPluginsLocalBinaries = { ->
    Set<String> binDeps = []

    // Retrieve the list of local plugins binaries.
    if (project.hasProperty("plugins_local_binaries")) {
        String pluginsList = project.property("plugins_local_binaries")
        if (pluginsList != null && !pluginsList.trim().isEmpty()) {
            for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
                binDeps += plugin.trim()
            }
        }
    }

    return binDeps
}

ext.getDebugKeystoreFile = { ->
    String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
    if (keystoreFile == null || keystoreFile.isEmpty()) {
        keystoreFile = "."
    }
    return keystoreFile
}

ext.hasCustomDebugKeystore = { ->
    File keystoreFile = new File(getDebugKeystoreFile())
    return keystoreFile.isFile()
}

ext.getDebugKeystorePassword = { ->
    String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
    if (keystorePassword == null || keystorePassword.isEmpty()) {
        keystorePassword = "android"
    }
    return keystorePassword
}

ext.getDebugKeyAlias = { ->
    String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
    if (keyAlias == null || keyAlias.isEmpty()) {
        keyAlias = "androiddebugkey"
    }
    return keyAlias
}

ext.getReleaseKeystoreFile = { ->
    String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
    if (keystoreFile == null || keystoreFile.isEmpty()) {
        keystoreFile = "."
    }
    return keystoreFile
}

ext.getReleaseKeystorePassword = { ->
    String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
    return keystorePassword
}

ext.getReleaseKeyAlias = { ->
    String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
    return keyAlias
}

ext.isAndroidStudio = { ->
    def sysProps = System.getProperties()
    return sysProps != null && sysProps['idea.platform.prefix'] != null
}

ext.shouldZipAlign = { ->
    String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
    if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
        if (isAndroidStudio()) {
            zipAlignFlag = "true"
        } else {
            zipAlignFlag = "false"
        }
    }
    return Boolean.parseBoolean(zipAlignFlag)
}

ext.shouldSign = { ->
    String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
    if (signFlag == null || signFlag.isEmpty()) {
        if (isAndroidStudio()) {
            signFlag = "true"
        } else {
            signFlag = "false"
        }
    }
    return Boolean.parseBoolean(signFlag)
}

ext.shouldNotStrip = { ->
    return isAndroidStudio() || project.hasProperty("doNotStrip")
}