build.gradle 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 'FULL' }
  80. }
  81. base {
  82. archivesName = "android_editor"
  83. }
  84. compileOptions {
  85. sourceCompatibility versions.javaVersion
  86. targetCompatibility versions.javaVersion
  87. }
  88. kotlinOptions {
  89. jvmTarget = versions.javaVersion
  90. }
  91. signingConfigs {
  92. release {
  93. storeFile getGodotKeystoreFile()
  94. storePassword getGodotSigningPassword()
  95. keyAlias getGodotKeyAlias()
  96. keyPassword getGodotSigningPassword()
  97. }
  98. }
  99. buildFeatures {
  100. buildConfig = true
  101. }
  102. buildTypes {
  103. dev {
  104. initWith debug
  105. applicationIdSuffix ".dev"
  106. manifestPlaceholders += [editorBuildSuffix: " (dev)"]
  107. }
  108. debug {
  109. initWith release
  110. applicationIdSuffix ".debug"
  111. manifestPlaceholders += [editorBuildSuffix: " (debug)"]
  112. signingConfig signingConfigs.debug
  113. }
  114. release {
  115. if (hasReleaseSigningConfigs()) {
  116. signingConfig signingConfigs.release
  117. }
  118. }
  119. }
  120. packagingOptions {
  121. // 'doNotStrip' is enabled for development within Android Studio
  122. if (shouldNotStrip()) {
  123. doNotStrip '**/*.so'
  124. }
  125. }
  126. flavorDimensions = ["android_distribution"]
  127. productFlavors {
  128. android {
  129. dimension "android_distribution"
  130. missingDimensionStrategy 'products', 'editor'
  131. }
  132. horizonos {
  133. dimension "android_distribution"
  134. missingDimensionStrategy 'products', 'editor'
  135. ndk {
  136. //noinspection ChromeOsAbiSupport
  137. abiFilters "arm64-v8a"
  138. }
  139. applicationIdSuffix ".meta"
  140. versionNameSuffix "-meta"
  141. minSdkVersion 23
  142. targetSdkVersion 32
  143. }
  144. picoos {
  145. dimension "android_distribution"
  146. missingDimensionStrategy 'products', 'editor'
  147. ndk {
  148. //noinspection ChromeOsAbiSupport
  149. abiFilters "arm64-v8a"
  150. }
  151. applicationIdSuffix ".pico"
  152. versionNameSuffix "-pico"
  153. minSdkVersion 29
  154. targetSdkVersion 32
  155. }
  156. }
  157. }
  158. dependencies {
  159. implementation "androidx.fragment:fragment:$versions.fragmentVersion"
  160. implementation project(":lib")
  161. implementation "androidx.window:window:1.3.0"
  162. implementation "androidx.core:core-splashscreen:$versions.splashscreenVersion"
  163. implementation "androidx.constraintlayout:constraintlayout:2.2.1"
  164. implementation "org.bouncycastle:bcprov-jdk15to18:1.78"
  165. // Meta dependencies
  166. horizonosImplementation "org.godotengine:godot-openxr-vendors-meta:$versions.openxrVendorsVersion"
  167. // Pico dependencies
  168. picoosImplementation "org.godotengine:godot-openxr-vendors-pico:$versions.openxrVendorsVersion"
  169. }