config.gradle 12 KB

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