build.gradle 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Gradle build config for Godot Engine's Android port.
  2. plugins {
  3. id 'com.android.application'
  4. id 'org.jetbrains.kotlin.android'
  5. }
  6. dependencies {
  7. implementation libraries.kotlinStdLib
  8. implementation libraries.androidxFragment
  9. implementation project(":lib")
  10. implementation "androidx.window:window:1.0.0"
  11. }
  12. ext {
  13. // Retrieve the build number from the environment variable; default to 0 if none is specified.
  14. // The build number is added as a suffix to the version code for upload to the Google Play store.
  15. getEditorBuildNumber = { ->
  16. int buildNumber = 0
  17. String versionStatus = System.getenv("GODOT_VERSION_STATUS")
  18. if (versionStatus != null && !versionStatus.isEmpty()) {
  19. try {
  20. buildNumber = Integer.parseInt(versionStatus.replaceAll("[^0-9]", ""));
  21. } catch (NumberFormatException ignored) {
  22. buildNumber = 0
  23. }
  24. }
  25. return buildNumber
  26. }
  27. // Value by which the Godot version code should be offset by to make room for the build number
  28. editorBuildNumberOffset = 100
  29. // Return the keystore file used for signing the release build.
  30. getGodotKeystoreFile = { ->
  31. def keyStore = System.getenv("GODOT_ANDROID_SIGN_KEYSTORE")
  32. if (keyStore == null) {
  33. return null
  34. }
  35. return file(keyStore)
  36. }
  37. // Return the key alias used for signing the release build.
  38. getGodotKeyAlias = { ->
  39. def kAlias = System.getenv("GODOT_ANDROID_KEYSTORE_ALIAS")
  40. return kAlias
  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. // Returns true if the environment variables contains the configuration for signing the release
  48. // build.
  49. hasReleaseSigningConfigs = { ->
  50. def keystoreFile = getGodotKeystoreFile()
  51. def keyAlias = getGodotKeyAlias()
  52. def signingPassword = getGodotSigningPassword()
  53. return keystoreFile != null && keystoreFile.isFile()
  54. && keyAlias != null && !keyAlias.isEmpty()
  55. && signingPassword != null && !signingPassword.isEmpty()
  56. }
  57. }
  58. def generateVersionCode() {
  59. int libraryVersionCode = getGodotLibraryVersionCode()
  60. return (libraryVersionCode * editorBuildNumberOffset) + getEditorBuildNumber()
  61. }
  62. def generateVersionName() {
  63. String libraryVersionName = getGodotLibraryVersionName()
  64. int buildNumber = getEditorBuildNumber()
  65. return buildNumber == 0 ? libraryVersionName : libraryVersionName + ".$buildNumber"
  66. }
  67. android {
  68. compileSdkVersion versions.compileSdk
  69. buildToolsVersion versions.buildTools
  70. ndkVersion versions.ndkVersion
  71. defaultConfig {
  72. // The 'applicationId' suffix allows to install Godot 3.x(v3) and 4.x(v4) on the same device
  73. applicationId "org.godotengine.editor.v4"
  74. versionCode generateVersionCode()
  75. versionName generateVersionName()
  76. minSdkVersion versions.minSdk
  77. targetSdkVersion versions.targetSdk
  78. missingDimensionStrategy 'products', 'editor'
  79. setProperty("archivesBaseName", "android_editor")
  80. }
  81. compileOptions {
  82. sourceCompatibility versions.javaVersion
  83. targetCompatibility versions.javaVersion
  84. }
  85. kotlinOptions {
  86. jvmTarget = versions.javaVersion
  87. }
  88. signingConfigs {
  89. release {
  90. storeFile getGodotKeystoreFile()
  91. storePassword getGodotSigningPassword()
  92. keyAlias getGodotKeyAlias()
  93. keyPassword getGodotSigningPassword()
  94. }
  95. }
  96. buildTypes {
  97. dev {
  98. initWith debug
  99. applicationIdSuffix ".dev"
  100. }
  101. debug {
  102. initWith release
  103. applicationIdSuffix ".debug"
  104. signingConfig signingConfigs.debug
  105. }
  106. release {
  107. if (hasReleaseSigningConfigs()) {
  108. signingConfig signingConfigs.release
  109. }
  110. }
  111. }
  112. packagingOptions {
  113. // 'doNotStrip' is enabled for development within Android Studio
  114. if (shouldNotStrip()) {
  115. doNotStrip '**/*.so'
  116. }
  117. }
  118. }