Skip to content
0.2.0-dev Download ZIP
262 lines ·9.1 KB Raw
1// Gradle build config for Godot Engine's Android port.
2plugins {
3 id 'com.android.application'
4 id 'org.jetbrains.kotlin.android'
5 id 'base'
6}
7
8ext {
9 // Retrieve the build number from the environment variable; default to 0 if none is specified.
10 // The build number is added as a suffix to the version code for upload to the Google Play store.
11 getEditorBuildNumber = { ->
12 int buildNumber = 0
13 String versionStatus = System.getenv("GODOT_VERSION_STATUS")
14 if (versionStatus != null && !versionStatus.isEmpty()) {
15 try {
16 buildNumber = Integer.parseInt(versionStatus.replaceAll("[^0-9]", ""))
17 } catch (NumberFormatException ignored) {
18 buildNumber = 0
19 }
20 }
21
22 return buildNumber
23 }
24 // Value by which the Godot version code should be offset by to make room for the build number
25 editorBuildNumberOffset = 100
26
27 // Return the keystore file used for signing the release build.
28 getGodotKeystoreFile = { ->
29 def keyStore = System.getenv("GODOT_ANDROID_SIGN_KEYSTORE")
30 if (keyStore == null || keyStore.isEmpty()) {
31 return null
32 }
33 return file(keyStore)
34 }
35
36 // Return the key alias used for signing the release build.
37 getGodotKeyAlias = { ->
38 def kAlias = System.getenv("GODOT_ANDROID_KEYSTORE_ALIAS")
39 return kAlias
40 }
41
42 // Return the password for the key used for signing the release build.
43 getGodotSigningPassword = { ->
44 def signingPassword = System.getenv("GODOT_ANDROID_SIGN_PASSWORD")
45 return signingPassword
46 }
47
48 // Returns true if the environment variables contains the configuration for signing the release
49 // build.
50 hasReleaseSigningConfigs = { ->
51 def keystoreFile = getGodotKeystoreFile()
52 def keyAlias = getGodotKeyAlias()
53 def signingPassword = getGodotSigningPassword()
54
55 return keystoreFile != null && keystoreFile.isFile()
56 && keyAlias != null && !keyAlias.isEmpty()
57 && signingPassword != null && !signingPassword.isEmpty()
58 }
59}
60
61def generateVersionCode() {
62 int libraryVersionCode = getGodotLibraryVersionCode()
63 return (libraryVersionCode * editorBuildNumberOffset) + getEditorBuildNumber()
64}
65
66def generateVersionName() {
67 String libraryVersionName = getGodotLibraryVersionName()
68 int buildNumber = getEditorBuildNumber()
69 return buildNumber == 0 ? libraryVersionName : libraryVersionName + ".$buildNumber"
70}
71
72android {
73 compileSdkVersion versions.compileSdk
74 buildToolsVersion versions.buildTools
75 ndkVersion = versions.ndkVersion
76
77 namespace = "org.godotengine.editor"
78
79 defaultConfig {
80 // The 'applicationId' suffix allows to install Godot 3.x(v3) and 4.x(v4) on the same device
81 applicationId "org.godotengine.editor.v4"
82 versionCode generateVersionCode()
83 versionName generateVersionName()
84 minSdkVersion versions.minSdk
85 targetSdkVersion versions.targetSdk
86
87 missingDimensionStrategy 'products', 'editor'
88 manifestPlaceholders += [
89 editorAppName: "Godot Engine 4",
90 editorBuildSuffix: ""
91 ]
92
93 ndk { debugSymbolLevel = 'NONE' }
94
95 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
96
97 // The following argument makes the Android Test Orchestrator run its
98 // "pm clear" command after each test invocation. This command ensures
99 // that the app's state is completely cleared between tests.
100 testInstrumentationRunnerArguments clearPackageData: 'true'
101 }
102
103 testOptions {
104 execution = 'ANDROIDX_TEST_ORCHESTRATOR'
105 }
106
107 base {
108 archivesName = "android_editor"
109 }
110
111 compileOptions {
112 sourceCompatibility versions.javaVersion
113 targetCompatibility versions.javaVersion
114 }
115
116 kotlinOptions {
117 jvmTarget = versions.javaVersion
118 }
119
120 signingConfigs {
121 release {
122 storeFile getGodotKeystoreFile()
123 storePassword getGodotSigningPassword()
124 keyAlias getGodotKeyAlias()
125 keyPassword getGodotSigningPassword()
126 }
127 }
128
129 buildFeatures {
130 buildConfig = true
131 }
132
133 buildTypes {
134 debug {
135 applicationIdSuffix ".debug"
136 manifestPlaceholders += [editorBuildSuffix: " (debug)"]
137 signingConfig = signingConfigs.debug
138 }
139
140 benchmark {
141 initWith release
142 applicationIdSuffix ".benchmark"
143 manifestPlaceholders += [editorBuildSuffix: " (benchmark)"]
144 signingConfig = signingConfigs.debug
145 matchingFallbacks = ['release']
146 debuggable false
147 }
148
149 release {
150 if (hasReleaseSigningConfigs()) {
151 signingConfig = signingConfigs.release
152 } else {
153 // We default to the debug signingConfigs when the release signing configs are not
154 // available (e.g: development in Android Studio).
155 signingConfig = signingConfigs.debug
156 // In addition, we update the application ID to allow installing an Android studio release build
157 // side by side with a production build from the store.
158 applicationIdSuffix ".release"
159 manifestPlaceholders += [editorBuildSuffix: " (release)"]
160 }
161 }
162 }
163
164 packagingOptions {
165 // Debug symbols are kept for development within Android Studio.
166 if (shouldNotStrip()) {
167 jniLibs {
168 keepDebugSymbols += '**/*.so'
169 }
170 }
171 }
172
173 flavorDimensions = ["android_distribution"]
174 productFlavors {
175 android {
176 dimension "android_distribution"
177 missingDimensionStrategy 'products', 'editor'
178 ndk {
179 if (!detectedAbis.isEmpty()) {
180 abiFilters += detectedAbis
181 }
182 }
183 }
184 horizonos {
185 dimension "android_distribution"
186 missingDimensionStrategy 'products', 'editor'
187 ndk {
188 //noinspection ChromeOsAbiSupport
189 abiFilters "arm64-v8a"
190 }
191 applicationIdSuffix ".meta"
192 versionNameSuffix "-meta"
193 targetSdkVersion 32
194 }
195 picoos {
196 dimension "android_distribution"
197 missingDimensionStrategy 'products', 'editor'
198 ndk {
199 //noinspection ChromeOsAbiSupport
200 abiFilters "arm64-v8a"
201 }
202 applicationIdSuffix ".pico"
203 versionNameSuffix "-pico"
204 minSdkVersion 29
205 targetSdkVersion 32
206 }
207 }
208}
209
210dependencies {
211 implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
212
213 implementation "androidx.fragment:fragment:$versions.fragmentVersion"
214 implementation project(":lib")
215
216 implementation "androidx.window:window:1.3.0"
217 implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
218 implementation "androidx.constraintlayout:constraintlayout:2.2.1"
219 implementation "org.bouncycastle:bcprov-jdk15to18:1.78"
220
221 implementation "org.khronos.openxr:openxr_loader_for_android:$versions.openxrLoaderVersion"
222 implementation "androidx.profileinstaller:profileinstaller:1.4.1"
223
224 // Android XR dependencies
225 androidImplementation "org.godotengine:godot-openxr-vendors-androidxr:$versions.openxrVendorsVersion"
226 androidImplementation "androidx.xr.scenecore:scenecore:1.0.0"
227
228 // Meta dependencies
229 horizonosImplementation "org.godotengine:godot-openxr-vendors-meta:$versions.openxrVendorsVersion"
230 // Pico dependencies
231 picoosImplementation "org.godotengine:godot-openxr-vendors-pico:$versions.openxrVendorsVersion"
232
233 // Android instrumented test dependencies
234 androidTestImplementation "androidx.test.ext:junit:$versions.junitVersion"
235 androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCoreVersion"
236 androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$versions.kotlinTestVersion"
237 androidTestImplementation "androidx.test:runner:$versions.testRunnerVersion"
238 androidTestUtil "androidx.test:orchestrator:$versions.testOrchestratorVersion"
239}
240
241/*
242 * Older versions of our vendor plugin include a loader that we no longer need.
243 * This code ensures those are removed.
244 */
245tasks.withType( com.android.build.gradle.internal.tasks.MergeNativeLibsTask) {
246 doFirst {
247 externalLibNativeLibs.each { jniDir ->
248 if (jniDir.getCanonicalPath().contains("godot-openxr-") || jniDir.getCanonicalPath().contains("godotopenxr")) {
249 // Delete the 'libopenxr_loader.so' files from the vendors plugin so we only use the version from the
250 // openxr loader dependency.
251 File armFile = new File(jniDir, "arm64-v8a/libopenxr_loader.so")
252 if (armFile.exists()) {
253 armFile.delete()
254 }
255 File x86File = new File(jniDir, "x86_64/libopenxr_loader.so")
256 if (x86File.exists()) {
257 x86File.delete()
258 }
259 }
260 }
261 }
262}