config.gradle 8.7 KB

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