| 1 |
// Gradle build config for Godot Engine's Android port. |
| 2 |
plugins { |
| 3 |
id 'com.android.application' |
| 4 |
id 'org.jetbrains.kotlin.android' |
| 5 |
id 'base' |
| 6 |
} |
| 7 |
|
| 8 |
ext { |
| 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 |
|
| 61 |
def generateVersionCode() { |
| 62 |
int libraryVersionCode = getGodotLibraryVersionCode() |
| 63 |
return (libraryVersionCode * editorBuildNumberOffset) + getEditorBuildNumber() |
| 64 |
} |
| 65 |
|
| 66 |
def generateVersionName() { |
| 67 |
String libraryVersionName = getGodotLibraryVersionName() |
| 68 |
int buildNumber = getEditorBuildNumber() |
| 69 |
return buildNumber == 0 ? libraryVersionName : libraryVersionName + ".$buildNumber" |
| 70 |
} |
| 71 |
|
| 72 |
android { |
| 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 |
dev { |
| 135 |
initWith debug |
| 136 |
applicationIdSuffix ".dev" |
| 137 |
manifestPlaceholders += [editorBuildSuffix: " (dev)"] |
| 138 |
} |
| 139 |
|
| 140 |
debug { |
| 141 |
initWith release |
| 142 |
applicationIdSuffix ".debug" |
| 143 |
manifestPlaceholders += [editorBuildSuffix: " (debug)"] |
| 144 |
signingConfig signingConfigs.debug |
| 145 |
} |
| 146 |
|
| 147 |
release { |
| 148 |
if (hasReleaseSigningConfigs()) { |
| 149 |
signingConfig signingConfigs.release |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
packagingOptions { |
| 155 |
// Debug symbols are kept for development within Android Studio. |
| 156 |
if (shouldNotStrip()) { |
| 157 |
jniLibs { |
| 158 |
keepDebugSymbols += '**/*.so' |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
flavorDimensions = ["android_distribution"] |
| 164 |
productFlavors { |
| 165 |
android { |
| 166 |
dimension "android_distribution" |
| 167 |
missingDimensionStrategy 'products', 'editor' |
| 168 |
} |
| 169 |
horizonos { |
| 170 |
dimension "android_distribution" |
| 171 |
missingDimensionStrategy 'products', 'editor' |
| 172 |
ndk { |
| 173 |
//noinspection ChromeOsAbiSupport |
| 174 |
abiFilters "arm64-v8a" |
| 175 |
} |
| 176 |
applicationIdSuffix ".meta" |
| 177 |
versionNameSuffix "-meta" |
| 178 |
targetSdkVersion 32 |
| 179 |
} |
| 180 |
picoos { |
| 181 |
dimension "android_distribution" |
| 182 |
missingDimensionStrategy 'products', 'editor' |
| 183 |
ndk { |
| 184 |
//noinspection ChromeOsAbiSupport |
| 185 |
abiFilters "arm64-v8a" |
| 186 |
} |
| 187 |
applicationIdSuffix ".pico" |
| 188 |
versionNameSuffix "-pico" |
| 189 |
minSdkVersion 29 |
| 190 |
targetSdkVersion 32 |
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
dependencies { |
| 196 |
implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"]) |
| 197 |
|
| 198 |
implementation "androidx.fragment:fragment:$versions.fragmentVersion" |
| 199 |
implementation project(":lib") |
| 200 |
|
| 201 |
implementation "androidx.window:window:1.3.0" |
| 202 |
implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion" |
| 203 |
implementation "androidx.constraintlayout:constraintlayout:2.2.1" |
| 204 |
implementation "org.bouncycastle:bcprov-jdk15to18:1.78" |
| 205 |
|
| 206 |
implementation "org.khronos.openxr:openxr_loader_for_android:$versions.openxrLoaderVersion" |
| 207 |
|
| 208 |
// Android XR dependencies |
| 209 |
androidImplementation "org.godotengine:godot-openxr-vendors-androidxr:$versions.openxrVendorsVersion" |
| 210 |
// Meta dependencies |
| 211 |
horizonosImplementation "org.godotengine:godot-openxr-vendors-meta:$versions.openxrVendorsVersion" |
| 212 |
// Pico dependencies |
| 213 |
picoosImplementation "org.godotengine:godot-openxr-vendors-pico:$versions.openxrVendorsVersion" |
| 214 |
|
| 215 |
// Android instrumented test dependencies |
| 216 |
androidTestImplementation "androidx.test.ext:junit:$versions.junitVersion" |
| 217 |
androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoCoreVersion" |
| 218 |
androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$versions.kotlinTestVersion" |
| 219 |
androidTestImplementation "androidx.test:runner:$versions.testRunnerVersion" |
| 220 |
androidTestUtil "androidx.test:orchestrator:$versions.testOrchestratorVersion" |
| 221 |
} |
| 222 |
|
| 223 |
/* |
| 224 |
* Older versions of our vendor plugin include a loader that we no longer need. |
| 225 |
* This code ensures those are removed. |
| 226 |
*/ |
| 227 |
tasks.withType( com.android.build.gradle.internal.tasks.MergeNativeLibsTask) { |
| 228 |
doFirst { |
| 229 |
externalLibNativeLibs.each { jniDir -> |
| 230 |
if (jniDir.getCanonicalPath().contains("godot-openxr-") || jniDir.getCanonicalPath().contains("godotopenxr")) { |
| 231 |
// Delete the 'libopenxr_loader.so' files from the vendors plugin so we only use the version from the |
| 232 |
// openxr loader dependency. |
| 233 |
File armFile = new File(jniDir, "arm64-v8a/libopenxr_loader.so") |
| 234 |
if (armFile.exists()) { |
| 235 |
armFile.delete() |
| 236 |
} |
| 237 |
File x86File = new File(jniDir, "x86_64/libopenxr_loader.so") |
| 238 |
if (x86File.exists()) { |
| 239 |
x86File.delete() |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
} |