config.gradle 11 KB

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