config.gradle 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. ext.versions = [
  2. androidGradlePlugin: '8.6.1',
  3. compileSdk : 35,
  4. minSdk : 21, // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
  5. targetSdk : 35, // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
  6. buildTools : '35.0.0',
  7. kotlinVersion : '2.1.20',
  8. fragmentVersion : '1.8.6',
  9. nexusPublishVersion: '1.3.0',
  10. javaVersion : JavaVersion.VERSION_17,
  11. ndkVersion : '28.1.13356709' // Also update 'platform/android/detect.py#get_ndk_version' when this is updated.
  12. ]
  13. ext.getExportPackageName = { ->
  14. // Retrieve the app id from the project property set by the Godot build command.
  15. String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
  16. // Check if the app id is valid, otherwise use the default.
  17. if (appId == null || appId.isEmpty()) {
  18. appId = "com.godot.game"
  19. }
  20. return appId
  21. }
  22. ext.getExportVersionCode = { ->
  23. String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
  24. if (versionCode == null || versionCode.isEmpty()) {
  25. versionCode = "1"
  26. }
  27. try {
  28. return Integer.parseInt(versionCode)
  29. } catch (NumberFormatException ignored) {
  30. return 1
  31. }
  32. }
  33. ext.getExportVersionName = { ->
  34. String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
  35. if (versionName == null || versionName.isEmpty()) {
  36. versionName = "1.0"
  37. }
  38. return versionName
  39. }
  40. ext.getExportMinSdkVersion = { ->
  41. String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
  42. if (minSdkVersion == null || minSdkVersion.isEmpty()) {
  43. minSdkVersion = "$versions.minSdk"
  44. }
  45. try {
  46. return Integer.parseInt(minSdkVersion)
  47. } catch (NumberFormatException ignored) {
  48. return versions.minSdk
  49. }
  50. }
  51. ext.getExportTargetSdkVersion = { ->
  52. String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
  53. if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
  54. targetSdkVersion = "$versions.targetSdk"
  55. }
  56. try {
  57. return Integer.parseInt(targetSdkVersion)
  58. } catch (NumberFormatException ignored) {
  59. return versions.targetSdk
  60. }
  61. }
  62. ext.getGodotEditorVersion = { ->
  63. String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
  64. if (editorVersion == null || editorVersion.isEmpty()) {
  65. // Try the library version first
  66. editorVersion = getGodotLibraryVersionName()
  67. if (editorVersion.isEmpty()) {
  68. // Fallback value.
  69. editorVersion = "custom_build"
  70. }
  71. }
  72. return editorVersion
  73. }
  74. ext.getGodotLibraryVersionCode = { ->
  75. String versionName = ""
  76. int versionCode = 1
  77. (versionName, versionCode) = getGodotLibraryVersion()
  78. return versionCode
  79. }
  80. ext.getGodotLibraryVersionName = { ->
  81. String versionName = ""
  82. int versionCode = 1
  83. (versionName, versionCode) = getGodotLibraryVersion()
  84. return versionName
  85. }
  86. ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
  87. // Attempt to read the version from the `version.py` file.
  88. String libraryVersionName = ""
  89. int libraryVersionCode = 0
  90. File versionFile = new File("../../../version.py")
  91. if (versionFile.isFile()) {
  92. def map = [:]
  93. List<String> lines = versionFile.readLines()
  94. for (String line in lines) {
  95. String[] keyValue = line.split("=")
  96. String key = keyValue[0].trim()
  97. String value = keyValue[1].trim().replaceAll("\"", "")
  98. if (requiredKeys.contains(key)) {
  99. if (!value.isEmpty()) {
  100. map[key] = value
  101. }
  102. requiredKeys.remove(key)
  103. }
  104. }
  105. if (requiredKeys.empty) {
  106. libraryVersionName = map.values().join(".")
  107. try {
  108. if (map.containsKey("status")) {
  109. int statusCode = 0
  110. String statusValue = map["status"]
  111. if (statusValue == null) {
  112. statusCode = 0
  113. } else if (statusValue.startsWith("dev")) {
  114. statusCode = 1
  115. } else if (statusValue.startsWith("alpha")) {
  116. statusCode = 2
  117. } else if (statusValue.startsWith("beta")) {
  118. statusCode = 3
  119. } else if (statusValue.startsWith("rc")) {
  120. statusCode = 4
  121. } else if (statusValue.startsWith("stable")) {
  122. statusCode = 5
  123. } else {
  124. statusCode = 0
  125. }
  126. libraryVersionCode = statusCode
  127. }
  128. if (map.containsKey("patch")) {
  129. libraryVersionCode += Integer.parseInt(map["patch"]) * 10
  130. }
  131. if (map.containsKey("minor")) {
  132. libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
  133. }
  134. if (map.containsKey("major")) {
  135. libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
  136. }
  137. } catch (NumberFormatException ignore) {
  138. libraryVersionCode = 1
  139. }
  140. }
  141. }
  142. if (libraryVersionName.isEmpty()) {
  143. // Fallback value in case we're unable to read the file.
  144. libraryVersionName = "custom_build"
  145. }
  146. if (libraryVersionCode == 0) {
  147. libraryVersionCode = 1
  148. }
  149. return [libraryVersionName, libraryVersionCode]
  150. }
  151. ext.getGodotLibraryVersion = { ->
  152. List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
  153. return generateGodotLibraryVersion(requiredKeys)
  154. }
  155. ext.getGodotPublishVersion = { ->
  156. List<String> requiredKeys = ["major", "minor", "patch", "status"]
  157. String versionName = ""
  158. int versionCode = 1
  159. (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
  160. if (!versionName.endsWith("stable")) {
  161. versionName += "-SNAPSHOT"
  162. }
  163. return versionName
  164. }
  165. final String VALUE_SEPARATOR_REGEX = "\\|"
  166. // get the list of ABIs the project should be exported to
  167. ext.getExportEnabledABIs = { ->
  168. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
  169. if (enabledABIs == null || enabledABIs.isEmpty()) {
  170. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  171. }
  172. Set<String> exportAbiFilter = [];
  173. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  174. if (!abi_name.trim().isEmpty()){
  175. exportAbiFilter.add(abi_name);
  176. }
  177. }
  178. return exportAbiFilter;
  179. }
  180. ext.getExportPath = {
  181. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  182. if (exportPath == null || exportPath.isEmpty()) {
  183. exportPath = "."
  184. }
  185. return exportPath
  186. }
  187. ext.getExportFilename = {
  188. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  189. if (exportFilename == null || exportFilename.isEmpty()) {
  190. exportFilename = "godot_android"
  191. }
  192. return exportFilename
  193. }
  194. /**
  195. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  196. * of maven repos.
  197. */
  198. ext.getGodotPluginsMavenRepos = { ->
  199. Set<String> mavenRepos = []
  200. // Retrieve the list of maven repos.
  201. if (project.hasProperty("plugins_maven_repos")) {
  202. String mavenReposProperty = project.property("plugins_maven_repos")
  203. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  204. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  205. mavenRepos += mavenRepoUrl.trim()
  206. }
  207. }
  208. }
  209. return mavenRepos
  210. }
  211. /**
  212. * Parse the project properties for the 'plugins_remote_binaries' property and return
  213. * it for inclusion in the build dependencies.
  214. */
  215. ext.getGodotPluginsRemoteBinaries = { ->
  216. Set<String> remoteDeps = []
  217. // Retrieve the list of remote plugins binaries.
  218. if (project.hasProperty("plugins_remote_binaries")) {
  219. String remoteDepsList = project.property("plugins_remote_binaries")
  220. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  221. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  222. remoteDeps += dep.trim()
  223. }
  224. }
  225. }
  226. return remoteDeps
  227. }
  228. /**
  229. * Parse the project properties for the 'plugins_local_binaries' property and return
  230. * their binaries for inclusion in the build dependencies.
  231. */
  232. ext.getGodotPluginsLocalBinaries = { ->
  233. Set<String> binDeps = []
  234. // Retrieve the list of local plugins binaries.
  235. if (project.hasProperty("plugins_local_binaries")) {
  236. String pluginsList = project.property("plugins_local_binaries")
  237. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  238. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  239. binDeps += plugin.trim()
  240. }
  241. }
  242. }
  243. return binDeps
  244. }
  245. ext.getDebugKeystoreFile = { ->
  246. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  247. if (keystoreFile == null || keystoreFile.isEmpty()) {
  248. keystoreFile = "."
  249. }
  250. return keystoreFile
  251. }
  252. ext.hasCustomDebugKeystore = { ->
  253. File keystoreFile = new File(getDebugKeystoreFile())
  254. return keystoreFile.isFile()
  255. }
  256. ext.getDebugKeystorePassword = { ->
  257. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  258. if (keystorePassword == null || keystorePassword.isEmpty()) {
  259. keystorePassword = "android"
  260. }
  261. return keystorePassword
  262. }
  263. ext.getDebugKeyAlias = { ->
  264. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  265. if (keyAlias == null || keyAlias.isEmpty()) {
  266. keyAlias = "androiddebugkey"
  267. }
  268. return keyAlias
  269. }
  270. ext.getReleaseKeystoreFile = { ->
  271. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  272. if (keystoreFile == null || keystoreFile.isEmpty()) {
  273. keystoreFile = "."
  274. }
  275. return keystoreFile
  276. }
  277. ext.getReleaseKeystorePassword = { ->
  278. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  279. return keystorePassword
  280. }
  281. ext.getReleaseKeyAlias = { ->
  282. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  283. return keyAlias
  284. }
  285. ext.isAndroidStudio = { ->
  286. def sysProps = System.getProperties()
  287. return sysProps != null && sysProps['idea.platform.prefix'] != null
  288. }
  289. ext.shouldZipAlign = { ->
  290. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  291. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  292. if (isAndroidStudio()) {
  293. zipAlignFlag = "true"
  294. } else {
  295. zipAlignFlag = "false"
  296. }
  297. }
  298. return Boolean.parseBoolean(zipAlignFlag)
  299. }
  300. ext.shouldSign = { ->
  301. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  302. if (signFlag == null || signFlag.isEmpty()) {
  303. if (isAndroidStudio()) {
  304. signFlag = "true"
  305. } else {
  306. signFlag = "false"
  307. }
  308. }
  309. return Boolean.parseBoolean(signFlag)
  310. }
  311. ext.shouldNotStrip = { ->
  312. return isAndroidStudio() || project.hasProperty("doNotStrip")
  313. }