build.gradle 8.2 KB

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