config.gradle 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ext.versions = [
  2. androidGradlePlugin: '4.0.1',
  3. compileSdk : 29,
  4. minSdk : 18,
  5. targetSdk : 29,
  6. buildTools : '30.0.3',
  7. supportCoreUtils : '1.0.0',
  8. kotlinVersion : '1.4.10',
  9. v4Support : '1.0.0',
  10. javaVersion : 1.8,
  11. ndkVersion : '21.4.7075529' // Also update 'platform/android/detect.py#get_project_ndk_version()' when this is updated.
  12. ]
  13. ext.libraries = [
  14. androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
  15. supportCoreUtils : "androidx.legacy:legacy-support-core-utils:$versions.supportCoreUtils",
  16. kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
  17. kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlinVersion",
  18. v4Support : "androidx.legacy:legacy-support-v4:$versions.v4Support"
  19. ]
  20. ext.getExportPackageName = { ->
  21. // Retrieve the app id from the project property set by the Godot build command.
  22. String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
  23. // Check if the app id is valid, otherwise use the default.
  24. if (appId == null || appId.isEmpty()) {
  25. appId = "com.godot.game"
  26. }
  27. return appId
  28. }
  29. ext.getExportVersionCode = { ->
  30. String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
  31. if (versionCode == null || versionCode.isEmpty()) {
  32. versionCode = "1"
  33. }
  34. try {
  35. return Integer.parseInt(versionCode)
  36. } catch (NumberFormatException ignored) {
  37. return 1
  38. }
  39. }
  40. ext.getExportVersionName = { ->
  41. String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
  42. if (versionName == null || versionName.isEmpty()) {
  43. versionName = "1.0"
  44. }
  45. return versionName
  46. }
  47. ext.getGodotEditorVersion = { ->
  48. String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
  49. if (editorVersion == null || editorVersion.isEmpty()) {
  50. // Try the library version first
  51. editorVersion = getGodotLibraryVersion()
  52. if (editorVersion.isEmpty()) {
  53. // Fallback value.
  54. editorVersion = "custom_build"
  55. }
  56. }
  57. return editorVersion
  58. }
  59. ext.getGodotLibraryVersion = { ->
  60. // Attempt to read the version from the `version.py` file.
  61. String libraryVersion = ""
  62. File versionFile = new File("../../../version.py")
  63. if (versionFile.isFile()) {
  64. List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
  65. def map = [:]
  66. List<String> lines = versionFile.readLines()
  67. for (String line in lines) {
  68. String[] keyValue = line.split("=")
  69. String key = keyValue[0].trim()
  70. String value = keyValue[1].trim().replaceAll("\"", "")
  71. if (requiredKeys.contains(key)) {
  72. if (!value.isEmpty()) {
  73. map[key] = value
  74. }
  75. requiredKeys.remove(key)
  76. }
  77. }
  78. if (requiredKeys.empty) {
  79. libraryVersion = map.values().join(".")
  80. }
  81. }
  82. if (libraryVersion.isEmpty()) {
  83. // Fallback value in case we're unable to read the file.
  84. libraryVersion = "custom_build"
  85. }
  86. return libraryVersion
  87. }
  88. final String VALUE_SEPARATOR_REGEX = "\\|"
  89. // get the list of ABIs the project should be exported to
  90. ext.getExportEnabledABIs = { ->
  91. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
  92. if (enabledABIs == null || enabledABIs.isEmpty()) {
  93. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  94. }
  95. Set<String> exportAbiFilter = [];
  96. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  97. if (!abi_name.trim().isEmpty()){
  98. exportAbiFilter.add(abi_name);
  99. }
  100. }
  101. return exportAbiFilter;
  102. }
  103. ext.getExportPath = {
  104. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  105. if (exportPath == null || exportPath.isEmpty()) {
  106. exportPath = "."
  107. }
  108. return exportPath
  109. }
  110. ext.getExportFilename = {
  111. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  112. if (exportFilename == null || exportFilename.isEmpty()) {
  113. exportFilename = "godot_android"
  114. }
  115. return exportFilename
  116. }
  117. /**
  118. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  119. * of maven repos.
  120. */
  121. ext.getGodotPluginsMavenRepos = { ->
  122. Set<String> mavenRepos = []
  123. // Retrieve the list of maven repos.
  124. if (project.hasProperty("plugins_maven_repos")) {
  125. String mavenReposProperty = project.property("plugins_maven_repos")
  126. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  127. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  128. mavenRepos += mavenRepoUrl.trim()
  129. }
  130. }
  131. }
  132. return mavenRepos
  133. }
  134. /**
  135. * Parse the project properties for the 'plugins_remote_binaries' property and return
  136. * it for inclusion in the build dependencies.
  137. */
  138. ext.getGodotPluginsRemoteBinaries = { ->
  139. Set<String> remoteDeps = []
  140. // Retrieve the list of remote plugins binaries.
  141. if (project.hasProperty("plugins_remote_binaries")) {
  142. String remoteDepsList = project.property("plugins_remote_binaries")
  143. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  144. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  145. remoteDeps += dep.trim()
  146. }
  147. }
  148. }
  149. return remoteDeps
  150. }
  151. /**
  152. * Parse the project properties for the 'plugins_local_binaries' property and return
  153. * their binaries for inclusion in the build dependencies.
  154. */
  155. ext.getGodotPluginsLocalBinaries = { ->
  156. Set<String> binDeps = []
  157. // Retrieve the list of local plugins binaries.
  158. if (project.hasProperty("plugins_local_binaries")) {
  159. String pluginsList = project.property("plugins_local_binaries")
  160. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  161. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  162. binDeps += plugin.trim()
  163. }
  164. }
  165. }
  166. return binDeps
  167. }
  168. ext.getReleaseKeystoreFile = { ->
  169. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  170. if (keystoreFile == null || keystoreFile.isEmpty()) {
  171. keystoreFile = "."
  172. }
  173. return keystoreFile
  174. }
  175. ext.getReleaseKeystorePassword = { ->
  176. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  177. return keystorePassword
  178. }
  179. ext.getReleaseKeyAlias = { ->
  180. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  181. return keyAlias
  182. }
  183. ext.isAndroidStudio = { ->
  184. def sysProps = System.getProperties()
  185. return sysProps != null && sysProps['idea.platform.prefix'] != null
  186. }
  187. ext.shouldZipAlign = { ->
  188. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  189. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  190. if (isAndroidStudio()) {
  191. zipAlignFlag = "true"
  192. } else {
  193. zipAlignFlag = "false"
  194. }
  195. }
  196. return Boolean.parseBoolean(zipAlignFlag)
  197. }
  198. ext.shouldSign = { ->
  199. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  200. if (signFlag == null || signFlag.isEmpty()) {
  201. if (isAndroidStudio()) {
  202. signFlag = "true"
  203. } else {
  204. signFlag = "false"
  205. }
  206. }
  207. return Boolean.parseBoolean(signFlag)
  208. }
  209. ext.shouldNotStrip = { ->
  210. return isAndroidStudio() || project.hasProperty("doNotStrip")
  211. }