config.gradle 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. ext.versions = [
  2. androidGradlePlugin: '8.2.0',
  3. compileSdk : 34,
  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 : 34,
  8. buildTools : '34.0.0',
  9. kotlinVersion : '1.9.20',
  10. fragmentVersion : '1.7.1',
  11. nexusPublishVersion: '1.3.0',
  12. javaVersion : JavaVersion.VERSION_17,
  13. // Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
  14. ndkVersion : '23.2.8568313',
  15. splashscreenVersion: '1.0.1',
  16. openxrVendorsVersion: '3.1.2-stable'
  17. ]
  18. ext.getExportPackageName = { ->
  19. // Retrieve the app id from the project property set by the Godot build command.
  20. String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
  21. // Check if the app id is valid, otherwise use the default.
  22. if (appId == null || appId.isEmpty()) {
  23. appId = "com.godot.game"
  24. }
  25. return appId
  26. }
  27. ext.getExportVersionCode = { ->
  28. String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
  29. if (versionCode == null || versionCode.isEmpty()) {
  30. versionCode = "1"
  31. }
  32. try {
  33. return Integer.parseInt(versionCode)
  34. } catch (NumberFormatException ignored) {
  35. return 1
  36. }
  37. }
  38. ext.getExportVersionName = { ->
  39. String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
  40. if (versionName == null || versionName.isEmpty()) {
  41. versionName = "1.0"
  42. }
  43. return versionName
  44. }
  45. ext.getExportMinSdkVersion = { ->
  46. String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
  47. if (minSdkVersion == null || minSdkVersion.isEmpty()) {
  48. minSdkVersion = "$versions.minSdk"
  49. }
  50. try {
  51. return Integer.parseInt(minSdkVersion)
  52. } catch (NumberFormatException ignored) {
  53. return versions.minSdk
  54. }
  55. }
  56. ext.getExportTargetSdkVersion = { ->
  57. String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
  58. if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
  59. targetSdkVersion = "$versions.targetSdk"
  60. }
  61. try {
  62. return Integer.parseInt(targetSdkVersion)
  63. } catch (NumberFormatException ignored) {
  64. return versions.targetSdk
  65. }
  66. }
  67. ext.getGodotRenderingMethod = { ->
  68. String renderingMethod = project.hasProperty("godot_rendering_method") ? project.property("godot_rendering_method") : ""
  69. return renderingMethod
  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. ext.getExportEdition = {
  204. String exportEdition = project.hasProperty("export_edition") ? project.property("export_edition") : ""
  205. if (exportEdition == null || exportEdition.isEmpty()) {
  206. exportEdition = "standard"
  207. }
  208. return exportEdition
  209. }
  210. ext.getExportBuildType = {
  211. String exportBuildType = project.hasProperty("export_build_type") ? project.property("export_build_type") : ""
  212. if (exportBuildType == null || exportBuildType.isEmpty()) {
  213. exportBuildType = "debug"
  214. }
  215. return exportBuildType
  216. }
  217. ext.getExportFormat = {
  218. String exportFormat = project.hasProperty("export_format") ? project.property("export_format") : ""
  219. if (exportFormat == null || exportFormat.isEmpty()) {
  220. exportFormat = "apk"
  221. }
  222. return exportFormat
  223. }
  224. /**
  225. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  226. * of maven repos.
  227. */
  228. ext.getGodotPluginsMavenRepos = { ->
  229. Set<String> mavenRepos = []
  230. // Retrieve the list of maven repos.
  231. if (project.hasProperty("plugins_maven_repos")) {
  232. String mavenReposProperty = project.property("plugins_maven_repos")
  233. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  234. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  235. mavenRepos += mavenRepoUrl.trim()
  236. }
  237. }
  238. }
  239. return mavenRepos
  240. }
  241. /**
  242. * Parse the project properties for the 'plugins_remote_binaries' property and return
  243. * it for inclusion in the build dependencies.
  244. */
  245. ext.getGodotPluginsRemoteBinaries = { ->
  246. Set<String> remoteDeps = []
  247. // Retrieve the list of remote plugins binaries.
  248. if (project.hasProperty("plugins_remote_binaries")) {
  249. String remoteDepsList = project.property("plugins_remote_binaries")
  250. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  251. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  252. remoteDeps += dep.trim()
  253. }
  254. }
  255. }
  256. return remoteDeps
  257. }
  258. /**
  259. * Parse the project properties for the 'plugins_local_binaries' property and return
  260. * their binaries for inclusion in the build dependencies.
  261. */
  262. ext.getGodotPluginsLocalBinaries = { ->
  263. Set<String> binDeps = []
  264. // Retrieve the list of local plugins binaries.
  265. if (project.hasProperty("plugins_local_binaries")) {
  266. String pluginsList = project.property("plugins_local_binaries")
  267. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  268. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  269. binDeps += plugin.trim()
  270. }
  271. }
  272. }
  273. return binDeps
  274. }
  275. ext.getDebugKeystoreFile = { ->
  276. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  277. if (keystoreFile == null || keystoreFile.isEmpty()) {
  278. keystoreFile = "."
  279. }
  280. return keystoreFile
  281. }
  282. ext.hasCustomDebugKeystore = { ->
  283. File keystoreFile = new File(getDebugKeystoreFile())
  284. return keystoreFile.isFile()
  285. }
  286. ext.getDebugKeystorePassword = { ->
  287. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  288. if (keystorePassword == null || keystorePassword.isEmpty()) {
  289. keystorePassword = "android"
  290. }
  291. return keystorePassword
  292. }
  293. ext.getDebugKeyAlias = { ->
  294. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  295. if (keyAlias == null || keyAlias.isEmpty()) {
  296. keyAlias = "androiddebugkey"
  297. }
  298. return keyAlias
  299. }
  300. ext.getReleaseKeystoreFile = { ->
  301. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  302. if (keystoreFile == null || keystoreFile.isEmpty()) {
  303. keystoreFile = "."
  304. }
  305. return keystoreFile
  306. }
  307. ext.getReleaseKeystorePassword = { ->
  308. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  309. return keystorePassword
  310. }
  311. ext.getReleaseKeyAlias = { ->
  312. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  313. return keyAlias
  314. }
  315. ext.isAndroidStudio = { ->
  316. return project.hasProperty('android.injected.invoked.from.ide')
  317. }
  318. ext.shouldZipAlign = { ->
  319. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  320. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  321. if (isAndroidStudio()) {
  322. zipAlignFlag = "true"
  323. } else {
  324. zipAlignFlag = "false"
  325. }
  326. }
  327. return Boolean.parseBoolean(zipAlignFlag)
  328. }
  329. ext.shouldSign = { ->
  330. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  331. if (signFlag == null || signFlag.isEmpty()) {
  332. if (isAndroidStudio()) {
  333. signFlag = "true"
  334. } else {
  335. signFlag = "false"
  336. }
  337. }
  338. return Boolean.parseBoolean(signFlag)
  339. }
  340. ext.shouldNotStrip = { ->
  341. return isAndroidStudio() || project.hasProperty("doNotStrip")
  342. }
  343. /**
  344. * Whether to use the legacy convention of compressing all .so files in the APK.
  345. *
  346. * For more background, see:
  347. * - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
  348. * - https://stackoverflow.com/a/44704840
  349. */
  350. ext.shouldUseLegacyPackaging = { ->
  351. int minSdk = getExportMinSdkVersion()
  352. if (minSdk < 23) {
  353. // Enforce the default behavior for compatibility with device running api < 23
  354. return true
  355. }
  356. String legacyPackagingFlag = project.hasProperty("compress_native_libraries") ? project.property("compress_native_libraries") : ""
  357. if (legacyPackagingFlag != null && !legacyPackagingFlag.isEmpty()) {
  358. return Boolean.parseBoolean(legacyPackagingFlag)
  359. }
  360. // Default behavior for minSdk >= 23
  361. return false
  362. }
  363. ext.getAddonsDirectory = { ->
  364. String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : ""
  365. return addonsDirectory
  366. }