build.gradle 6.0 KB

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