config.gradle 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. ext.versions = [
  2. androidGradlePlugin: '7.2.1',
  3. compileSdk : 32,
  4. // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
  5. minSdk : 21,
  6. // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
  7. targetSdk : 32,
  8. buildTools : '32.0.0',
  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. return versionName
  168. }
  169. final String VALUE_SEPARATOR_REGEX = "\\|"
  170. // get the list of ABIs the project should be exported to
  171. ext.getExportEnabledABIs = { ->
  172. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
  173. if (enabledABIs == null || enabledABIs.isEmpty()) {
  174. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  175. }
  176. Set<String> exportAbiFilter = [];
  177. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  178. if (!abi_name.trim().isEmpty()){
  179. exportAbiFilter.add(abi_name);
  180. }
  181. }
  182. return exportAbiFilter;
  183. }
  184. ext.getExportPath = {
  185. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  186. if (exportPath == null || exportPath.isEmpty()) {
  187. exportPath = "."
  188. }
  189. return exportPath
  190. }
  191. ext.getExportFilename = {
  192. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  193. if (exportFilename == null || exportFilename.isEmpty()) {
  194. exportFilename = "godot_android"
  195. }
  196. return exportFilename
  197. }
  198. /**
  199. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  200. * of maven repos.
  201. */
  202. ext.getGodotPluginsMavenRepos = { ->
  203. Set<String> mavenRepos = []
  204. // Retrieve the list of maven repos.
  205. if (project.hasProperty("plugins_maven_repos")) {
  206. String mavenReposProperty = project.property("plugins_maven_repos")
  207. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  208. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  209. mavenRepos += mavenRepoUrl.trim()
  210. }
  211. }
  212. }
  213. return mavenRepos
  214. }
  215. /**
  216. * Parse the project properties for the 'plugins_remote_binaries' property and return
  217. * it for inclusion in the build dependencies.
  218. */
  219. ext.getGodotPluginsRemoteBinaries = { ->
  220. Set<String> remoteDeps = []
  221. // Retrieve the list of remote plugins binaries.
  222. if (project.hasProperty("plugins_remote_binaries")) {
  223. String remoteDepsList = project.property("plugins_remote_binaries")
  224. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  225. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  226. remoteDeps += dep.trim()
  227. }
  228. }
  229. }
  230. return remoteDeps
  231. }
  232. /**
  233. * Parse the project properties for the 'plugins_local_binaries' property and return
  234. * their binaries for inclusion in the build dependencies.
  235. */
  236. ext.getGodotPluginsLocalBinaries = { ->
  237. Set<String> binDeps = []
  238. // Retrieve the list of local plugins binaries.
  239. if (project.hasProperty("plugins_local_binaries")) {
  240. String pluginsList = project.property("plugins_local_binaries")
  241. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  242. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  243. binDeps += plugin.trim()
  244. }
  245. }
  246. }
  247. return binDeps
  248. }
  249. ext.getDebugKeystoreFile = { ->
  250. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  251. if (keystoreFile == null || keystoreFile.isEmpty()) {
  252. keystoreFile = "."
  253. }
  254. return keystoreFile
  255. }
  256. ext.hasCustomDebugKeystore = { ->
  257. File keystoreFile = new File(getDebugKeystoreFile())
  258. return keystoreFile.isFile()
  259. }
  260. ext.getDebugKeystorePassword = { ->
  261. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  262. if (keystorePassword == null || keystorePassword.isEmpty()) {
  263. keystorePassword = "android"
  264. }
  265. return keystorePassword
  266. }
  267. ext.getDebugKeyAlias = { ->
  268. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  269. if (keyAlias == null || keyAlias.isEmpty()) {
  270. keyAlias = "androiddebugkey"
  271. }
  272. return keyAlias
  273. }
  274. ext.getReleaseKeystoreFile = { ->
  275. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  276. if (keystoreFile == null || keystoreFile.isEmpty()) {
  277. keystoreFile = "."
  278. }
  279. return keystoreFile
  280. }
  281. ext.getReleaseKeystorePassword = { ->
  282. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  283. return keystorePassword
  284. }
  285. ext.getReleaseKeyAlias = { ->
  286. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  287. return keyAlias
  288. }
  289. ext.isAndroidStudio = { ->
  290. def sysProps = System.getProperties()
  291. return sysProps != null && sysProps['idea.platform.prefix'] != null
  292. }
  293. ext.shouldZipAlign = { ->
  294. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  295. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  296. if (isAndroidStudio()) {
  297. zipAlignFlag = "true"
  298. } else {
  299. zipAlignFlag = "false"
  300. }
  301. }
  302. return Boolean.parseBoolean(zipAlignFlag)
  303. }
  304. ext.shouldSign = { ->
  305. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  306. if (signFlag == null || signFlag.isEmpty()) {
  307. if (isAndroidStudio()) {
  308. signFlag = "true"
  309. } else {
  310. signFlag = "false"
  311. }
  312. }
  313. return Boolean.parseBoolean(signFlag)
  314. }
  315. ext.shouldNotStrip = { ->
  316. return isAndroidStudio() || project.hasProperty("doNotStrip")
  317. }