Debian Codegraph @

platform/android/java/app/build.gradle

raw
1 // Gradle build config for Godot Engine's Android port.
2 plugins {
3 id 'com.android.application'
4 id 'org.jetbrains.kotlin.android'
5 }
6
7 apply from: 'config.gradle'
8
9 allprojects {
10 repositories {
11 google()
12 mavenCentral()
13 gradlePluginPortal()
14 maven { url "https://plugins.gradle.org/m2/" }
15 maven { url "https://central.sonatype.com/repository/maven-snapshots/"}
16
17 // Godot user plugins custom maven repos
18 String[] mavenRepos = getGodotPluginsMavenRepos()
19 if (mavenRepos != null && mavenRepos.size() > 0) {
20 for (String repoUrl : mavenRepos) {
21 maven {
22 url repoUrl
23 }
24 }
25 }
26 }
27 }
28
29 configurations {
30 // Initializes a placeholder for the devImplementation dependency configuration.
31 devImplementation {}
32 // Initializes a placeholder for the monoImplementation dependency configuration.
33 monoImplementation {}
34 }
35
36 dependencies {
37 // Android instrumented test dependencies
38 androidTestImplementation "androidx.test.ext:junit:$versions.junitVersion"
39 androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCoreVersion"
40 androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$versions.kotlinTestVersion"
41 androidTestImplementation "androidx.test:runner:$versions.testRunnerVersion"
42 androidTestUtil "androidx.test:orchestrator:$versions.testOrchestratorVersion"
43
44 implementation "androidx.fragment:fragment:$versions.fragmentVersion"
45 implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
46 implementation "androidx.documentfile:documentfile:$versions.documentfileVersion"
47
48 if (rootProject.findProject(":lib")) {
49 implementation project(":lib")
50 } else if (rootProject.findProject(":godot:lib")) {
51 implementation project(":godot:lib")
52 } else {
53 // Godot gradle build mode. In this scenario this project is the only one around and the Godot
54 // library is available through the pre-generated godot-lib.*.aar android archive files.
55 debugImplementation fileTree(dir: 'libs/debug', include: ['**/*.jar', '*.aar'])
56 devImplementation fileTree(dir: 'libs/dev', include: ['**/*.jar', '*.aar'])
57 releaseImplementation fileTree(dir: 'libs/release', include: ['**/*.jar', '*.aar'])
58 }
59
60 // Godot user plugins remote dependencies
61 String[] remoteDeps = getGodotPluginsRemoteBinaries()
62 if (remoteDeps != null && remoteDeps.size() > 0) {
63 for (String dep : remoteDeps) {
64 implementation dep
65 }
66 }
67
68 // Godot user plugins local dependencies
69 String[] pluginsBinaries = getGodotPluginsLocalBinaries()
70 if (pluginsBinaries != null && pluginsBinaries.size() > 0) {
71 implementation files(pluginsBinaries)
72 }
73
74 // Automatically pick up local dependencies in res://addons
75 String addonsDirectory = getAddonsDirectory()
76 if (addonsDirectory != null && !addonsDirectory.isBlank()) {
77 implementation fileTree(dir: "$addonsDirectory", include: ['*.jar', '*.aar'])
78 }
79
80 // .NET dependencies
81 String jar = '../../../../modules/mono/thirdparty/libSystem.Security.Cryptography.Native.Android.jar'
82 if (file(jar).exists()) {
83 monoImplementation files(jar)
84 }
85 }
86
87 android {
88 compileSdkVersion versions.compileSdk
89 buildToolsVersion versions.buildTools
90 ndkVersion versions.ndkVersion
91
92 compileOptions {
93 sourceCompatibility versions.javaVersion
94 targetCompatibility versions.javaVersion
95 }
96
97 kotlinOptions {
98 jvmTarget = versions.javaVersion
99 }
100
101 assetPacks = [":assetPackInstallTime"]
102
103 namespace = 'com.godot.game'
104
105 defaultConfig {
106 // The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
107 aaptOptions {
108 ignoreAssetsPattern "!.svn:!.git:!.gitignore:!.ds_store:!*.scc:!CVS:!thumbs.db:!picasa.ini:!*~"
109 }
110
111 ndk {
112 debugSymbolLevel 'NONE'
113 String[] export_abi_list = getExportEnabledABIs()
114 abiFilters export_abi_list
115 }
116
117 // Feel free to modify the application id to your own.
118 applicationId getExportPackageName()
119 versionCode getExportVersionCode()
120 versionName getExportVersionName()
121 minSdkVersion getExportMinSdkVersion()
122 targetSdkVersion getExportTargetSdkVersion()
123
124 missingDimensionStrategy 'products', 'template'
125
126 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
127
128 // The following argument makes the Android Test Orchestrator run its
129 // "pm clear" command after each test invocation. This command ensures
130 // that the app's state is completely cleared between tests.
131 testInstrumentationRunnerArguments clearPackageData: 'true'
132 }
133
134 testOptions {
135 execution 'ANDROIDX_TEST_ORCHESTRATOR'
136 }
137
138 lintOptions {
139 abortOnError false
140 disable 'MissingTranslation', 'UnusedResources'
141 }
142
143 ndkVersion versions.ndkVersion
144
145 packagingOptions {
146 exclude 'META-INF/LICENSE'
147 exclude 'META-INF/NOTICE'
148
149 // Debug symbols are kept for development within Android Studio.
150 if (shouldNotStrip()) {
151 jniLibs {
152 keepDebugSymbols += '**/*.so'
153 }
154 }
155
156 jniLibs {
157 // Setting this to true causes AGP to package compressed native libraries when building the app
158 // For more background, see:
159 // - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
160 // - https://stackoverflow.com/a/44704840
161 useLegacyPackaging shouldUseLegacyPackaging()
162 }
163
164 // Always select Godot's version of libc++_shared.so in case deps have their own
165 pickFirst 'lib/x86/libc++_shared.so'
166 pickFirst 'lib/x86_64/libc++_shared.so'
167 pickFirst 'lib/armeabi-v7a/libc++_shared.so'
168 pickFirst 'lib/arm64-v8a/libc++_shared.so'
169 }
170
171 signingConfigs {
172 debug {
173 if (hasCustomDebugKeystore()) {
174 storeFile new File(getDebugKeystoreFile())
175 storePassword getDebugKeystorePassword()
176 keyAlias getDebugKeyAlias()
177 keyPassword getDebugKeystorePassword()
178 }
179 }
180
181 release {
182 File keystoreFile = new File(getReleaseKeystoreFile())
183 if (keystoreFile.isFile()) {
184 storeFile keystoreFile
185 storePassword getReleaseKeystorePassword()
186 keyAlias getReleaseKeyAlias()
187 keyPassword getReleaseKeystorePassword()
188 }
189 }
190 }
191
192 buildFeatures {
193 buildConfig = true
194 }
195
196 buildTypes {
197
198 debug {
199 // Signing and zip-aligning are skipped for prebuilt builds, but
200 // performed for Godot gradle builds.
201 zipAlignEnabled shouldZipAlign()
202 if (shouldSign()) {
203 signingConfig signingConfigs.debug
204 } else {
205 signingConfig null
206 }
207 }
208
209 dev {
210 initWith debug
211 // Signing and zip-aligning are skipped for prebuilt builds, but
212 // performed for Godot gradle builds.
213 zipAlignEnabled shouldZipAlign()
214 if (shouldSign()) {
215 signingConfig signingConfigs.debug
216 } else {
217 signingConfig null
218 }
219 }
220
221 release {
222 // Signing and zip-aligning are skipped for prebuilt builds, but
223 // performed for Godot gradle builds.
224 zipAlignEnabled shouldZipAlign()
225 if (shouldSign()) {
226 signingConfig signingConfigs.release
227 } else {
228 signingConfig null
229 }
230 }
231 }
232
233 flavorDimensions 'edition'
234
235 productFlavors {
236 // Product flavor for the standard (no .net support) builds.
237 standard {
238 getIsDefault().set(true)
239 }
240
241 // Product flavor for the Mono (.net) builds.
242 mono {}
243
244 // Product flavor used for running instrumented tests.
245 instrumented {
246 applicationIdSuffix ".instrumented"
247 versionNameSuffix "-instrumented"
248 }
249 }
250
251 sourceSets {
252 main.res.srcDirs += ['res']
253 debug.jniLibs.srcDirs = ['libs/debug', 'libs/debug/vulkan_validation_layers']
254 dev.jniLibs.srcDirs = ['libs/dev']
255 release.jniLibs.srcDirs = ['libs/release']
256 }
257
258 applicationVariants.all { variant ->
259 variant.outputs.all { output ->
260 String filenameSuffix = variant.flavorName == "mono" ? variant.name : variant.buildType.name
261 output.outputFileName = "android_${filenameSuffix}.apk"
262 }
263 }
264 }
265
266 task copyAndRenameBinary(type: Copy) {
267 // The 'doNotTrackState' is added to disable gradle's up-to-date checks for output files
268 // and directories. Otherwise this check may cause permissions access failures on Windows
269 // machines.
270 doNotTrackState("No need for up-to-date checks for the copy-and-rename operation")
271
272 String exportPath = getExportPath()
273 String exportFilename = getExportFilename()
274 String exportEdition = getExportEdition()
275 String exportBuildType = getExportBuildType()
276 String exportBuildTypeCapitalized = exportBuildType.capitalize()
277 String exportFormat = getExportFormat()
278
279 boolean isAab = exportFormat == "aab"
280 boolean isMono = exportEdition == "mono"
281 String filenameSuffix = isAab ? "${exportEdition}-${exportBuildType}" : exportBuildType
282 if (isMono) {
283 filenameSuffix = isAab ? "${exportEdition}-${exportBuildType}" : "${exportEdition}${exportBuildTypeCapitalized}"
284 }
285
286 String sourceFilename = isAab ? "${project.name}-${filenameSuffix}.aab" : "android_${filenameSuffix}.apk"
287 String sourceFilepath = isAab ? "$buildDir/outputs/bundle/${exportEdition}${exportBuildTypeCapitalized}/$sourceFilename" : "$buildDir/outputs/apk/$exportEdition/$exportBuildType/$sourceFilename"
288
289 from sourceFilepath
290 into exportPath
291 rename sourceFilename, exportFilename
292 }
293
294 /**
295 * Used to validate the version of the Java SDK used for the Godot gradle builds.
296 */
297 task validateJavaVersion {
298 if (!JavaVersion.current().isCompatibleWith(versions.javaVersion)) {
299 throw new GradleException("Invalid Java version ${JavaVersion.current()}. Version ${versions.javaVersion} is the minimum supported Java version for Godot gradle builds.")
300 }
301 }
302
303 /*
304 * Older versions of our vendor plugin include a loader that we no longer need.
305 * This code ensures those are removed.
306 */
307 tasks.withType( com.android.build.gradle.internal.tasks.MergeNativeLibsTask) {
308 doFirst {
309 externalLibNativeLibs.each { jniDir ->
310 if (jniDir.getCanonicalPath().contains("godot-openxr-") || jniDir.getCanonicalPath().contains("godotopenxr")) {
311 // Delete the 'libopenxr_loader.so' files from the vendors plugin so we only use the version from the
312 // openxr loader dependency.
313 File armFile = new File(jniDir, "arm64-v8a/libopenxr_loader.so")
314 if (armFile.exists()) {
315 armFile.delete()
316 }
317 File x86File = new File(jniDir, "x86_64/libopenxr_loader.so")
318 if (x86File.exists()) {
319 x86File.delete()
320 }
321 }
322 }
323 }
324 }
325
326 /*
327 When they're scheduled to run, the copy*AARToAppModule tasks generate dependencies for the 'app'
328 module, so we're ensuring the ':app:preBuild' task is set to run after those tasks.
329 */
330 if (rootProject.tasks.findByPath("copyDebugAARToAppModule") != null) {
331 preBuild.mustRunAfter(rootProject.tasks.named("copyDebugAARToAppModule"))
332 }
333 if (rootProject.tasks.findByPath("copyDevAARToAppModule") != null) {
334 preBuild.mustRunAfter(rootProject.tasks.named("copyDevAARToAppModule"))
335 }
336 if (rootProject.tasks.findByPath("copyReleaseAARToAppModule") != null) {
337 preBuild.mustRunAfter(rootProject.tasks.named("copyReleaseAARToAppModule"))
338 }