config.gradle 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. ext.versions = [
  2. androidGradlePlugin: '7.2.1',
  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("dev")) {
  123. statusCode = 1
  124. } else if (statusValue.startsWith("alpha")) {
  125. statusCode = 2
  126. } else if (statusValue.startsWith("beta")) {
  127. statusCode = 3
  128. } else if (statusValue.startsWith("rc")) {
  129. statusCode = 4
  130. } else if (statusValue.startsWith("stable")) {
  131. statusCode = 5
  132. } else {
  133. statusCode = 0
  134. }
  135. libraryVersionCode = statusCode
  136. }
  137. if (map.containsKey("patch")) {
  138. libraryVersionCode += Integer.parseInt(map["patch"]) * 10
  139. }
  140. if (map.containsKey("minor")) {
  141. libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
  142. }
  143. if (map.containsKey("major")) {
  144. libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
  145. }
  146. } catch (NumberFormatException ignore) {
  147. libraryVersionCode = 1
  148. }
  149. }
  150. }
  151. if (libraryVersionName.isEmpty()) {
  152. // Fallback value in case we're unable to read the file.
  153. libraryVersionName = "custom_build"
  154. }
  155. if (libraryVersionCode == 0) {
  156. libraryVersionCode = 1
  157. }
  158. return [libraryVersionName, libraryVersionCode]
  159. }
  160. ext.getGodotLibraryVersion = { ->
  161. List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
  162. return generateGodotLibraryVersion(requiredKeys)
  163. }
  164. ext.getGodotPublishVersion = { ->
  165. List<String> requiredKeys = ["major", "minor", "patch", "status"]
  166. String versionName = ""
  167. int versionCode = 1
  168. (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
  169. if (!versionName.endsWith("stable")) {
  170. versionName += "-SNAPSHOT"
  171. }
  172. return versionName
  173. }
  174. final String VALUE_SEPARATOR_REGEX = "\\|"
  175. // get the list of ABIs the project should be exported to
  176. ext.getExportEnabledABIs = { ->
  177. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
  178. if (enabledABIs == null || enabledABIs.isEmpty()) {
  179. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  180. }
  181. Set<String> exportAbiFilter = [];
  182. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  183. if (!abi_name.trim().isEmpty()){
  184. exportAbiFilter.add(abi_name);
  185. }
  186. }
  187. return exportAbiFilter;
  188. }
  189. ext.getExportPath = {
  190. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  191. if (exportPath == null || exportPath.isEmpty()) {
  192. exportPath = "."
  193. }
  194. return exportPath
  195. }
  196. ext.getExportFilename = {
  197. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  198. if (exportFilename == null || exportFilename.isEmpty()) {
  199. exportFilename = "godot_android"
  200. }
  201. return exportFilename
  202. }
  203. /**
  204. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  205. * of maven repos.
  206. */
  207. ext.getGodotPluginsMavenRepos = { ->
  208. Set<String> mavenRepos = []
  209. // Retrieve the list of maven repos.
  210. if (project.hasProperty("plugins_maven_repos")) {
  211. String mavenReposProperty = project.property("plugins_maven_repos")
  212. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  213. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  214. mavenRepos += mavenRepoUrl.trim()
  215. }
  216. }
  217. }
  218. return mavenRepos
  219. }
  220. /**
  221. * Parse the project properties for the 'plugins_remote_binaries' property and return
  222. * it for inclusion in the build dependencies.
  223. */
  224. ext.getGodotPluginsRemoteBinaries = { ->
  225. Set<String> remoteDeps = []
  226. // Retrieve the list of remote plugins binaries.
  227. if (project.hasProperty("plugins_remote_binaries")) {
  228. String remoteDepsList = project.property("plugins_remote_binaries")
  229. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  230. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  231. remoteDeps += dep.trim()
  232. }
  233. }
  234. }
  235. return remoteDeps
  236. }
  237. /**
  238. * Parse the project properties for the 'plugins_local_binaries' property and return
  239. * their binaries for inclusion in the build dependencies.
  240. */
  241. ext.getGodotPluginsLocalBinaries = { ->
  242. Set<String> binDeps = []
  243. // Retrieve the list of local plugins binaries.
  244. if (project.hasProperty("plugins_local_binaries")) {
  245. String pluginsList = project.property("plugins_local_binaries")
  246. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  247. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  248. binDeps += plugin.trim()
  249. }
  250. }
  251. }
  252. return binDeps
  253. }
  254. ext.getDebugKeystoreFile = { ->
  255. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  256. if (keystoreFile == null || keystoreFile.isEmpty()) {
  257. keystoreFile = "."
  258. }
  259. return keystoreFile
  260. }
  261. ext.hasCustomDebugKeystore = { ->
  262. File keystoreFile = new File(getDebugKeystoreFile())
  263. return keystoreFile.isFile()
  264. }
  265. ext.getDebugKeystorePassword = { ->
  266. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  267. if (keystorePassword == null || keystorePassword.isEmpty()) {
  268. keystorePassword = "android"
  269. }
  270. return keystorePassword
  271. }
  272. ext.getDebugKeyAlias = { ->
  273. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  274. if (keyAlias == null || keyAlias.isEmpty()) {
  275. keyAlias = "androiddebugkey"
  276. }
  277. return keyAlias
  278. }
  279. ext.getReleaseKeystoreFile = { ->
  280. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  281. if (keystoreFile == null || keystoreFile.isEmpty()) {
  282. keystoreFile = "."
  283. }
  284. return keystoreFile
  285. }
  286. ext.getReleaseKeystorePassword = { ->
  287. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  288. return keystorePassword
  289. }
  290. ext.getReleaseKeyAlias = { ->
  291. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  292. return keyAlias
  293. }
  294. ext.isAndroidStudio = { ->
  295. def sysProps = System.getProperties()
  296. return sysProps != null && sysProps['idea.platform.prefix'] != null
  297. }
  298. ext.shouldZipAlign = { ->
  299. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  300. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  301. if (isAndroidStudio()) {
  302. zipAlignFlag = "true"
  303. } else {
  304. zipAlignFlag = "false"
  305. }
  306. }
  307. return Boolean.parseBoolean(zipAlignFlag)
  308. }
  309. ext.shouldSign = { ->
  310. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  311. if (signFlag == null || signFlag.isEmpty()) {
  312. if (isAndroidStudio()) {
  313. signFlag = "true"
  314. } else {
  315. signFlag = "false"
  316. }
  317. }
  318. return Boolean.parseBoolean(signFlag)
  319. }
  320. ext.shouldNotStrip = { ->
  321. return isAndroidStudio() || project.hasProperty("doNotStrip")
  322. }