config.gradle 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. ext.versions = [
  2. androidGradlePlugin: '8.6.1',
  3. compileSdk : 35,
  4. // Also update:
  5. // - 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
  6. // - 'platform/android/detect.py#get_min_target_api()'
  7. minSdk : 24,
  8. // Also update 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
  9. targetSdk : 35,
  10. buildTools : '35.0.1',
  11. kotlinVersion : '2.1.20',
  12. fragmentVersion : '1.8.6',
  13. nexusPublishVersion: '1.3.0',
  14. javaVersion : JavaVersion.VERSION_17,
  15. // Also update 'platform/android/detect.py#get_ndk_version()' when this is updated.
  16. ndkVersion : '28.1.13356709',
  17. splashscreenVersion: '1.0.1',
  18. // 'openxrLoaderVersion' should be set to XR_CURRENT_API_VERSION, see 'thirdparty/openxr'
  19. openxrLoaderVersion: '1.1.53',
  20. openxrVendorsVersion: '4.2.2-stable',
  21. junitVersion : '1.3.0',
  22. espressoCoreVersion: '3.7.0',
  23. kotlinTestVersion : '1.3.11',
  24. testRunnerVersion : '1.7.0',
  25. testOrchestratorVersion: '1.6.1',
  26. ]
  27. ext.getExportPackageName = { ->
  28. // Retrieve the app id from the project property set by the Godot build command.
  29. String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
  30. // Check if the app id is valid, otherwise use the default.
  31. if (appId == null || appId.isEmpty()) {
  32. appId = "com.godot.game"
  33. }
  34. return appId
  35. }
  36. ext.getExportVersionCode = { ->
  37. String versionCode = project.hasProperty("export_version_code") ? project.property("export_version_code") : ""
  38. if (versionCode == null || versionCode.isEmpty()) {
  39. versionCode = "1"
  40. }
  41. try {
  42. return Integer.parseInt(versionCode)
  43. } catch (NumberFormatException ignored) {
  44. return 1
  45. }
  46. }
  47. ext.getExportVersionName = { ->
  48. String versionName = project.hasProperty("export_version_name") ? project.property("export_version_name") : ""
  49. if (versionName == null || versionName.isEmpty()) {
  50. versionName = "1.0"
  51. }
  52. return versionName
  53. }
  54. ext.getExportMinSdkVersion = { ->
  55. String minSdkVersion = project.hasProperty("export_version_min_sdk") ? project.property("export_version_min_sdk") : ""
  56. if (minSdkVersion == null || minSdkVersion.isEmpty()) {
  57. minSdkVersion = "$versions.minSdk"
  58. }
  59. try {
  60. return Integer.parseInt(minSdkVersion)
  61. } catch (NumberFormatException ignored) {
  62. return versions.minSdk
  63. }
  64. }
  65. ext.getExportTargetSdkVersion = { ->
  66. String targetSdkVersion = project.hasProperty("export_version_target_sdk") ? project.property("export_version_target_sdk") : ""
  67. if (targetSdkVersion == null || targetSdkVersion.isEmpty()) {
  68. targetSdkVersion = "$versions.targetSdk"
  69. }
  70. try {
  71. return Integer.parseInt(targetSdkVersion)
  72. } catch (NumberFormatException ignored) {
  73. return versions.targetSdk
  74. }
  75. }
  76. ext.getGodotLibraryVersionCode = { ->
  77. String versionName = ""
  78. int versionCode = 1
  79. (versionName, versionCode) = getGodotLibraryVersion()
  80. return versionCode
  81. }
  82. ext.getGodotLibraryVersionName = { ->
  83. String versionName = ""
  84. int versionCode = 1
  85. (versionName, versionCode) = getGodotLibraryVersion()
  86. return versionName
  87. }
  88. ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
  89. // Attempt to read the version from the `version.py` file.
  90. String libraryVersionName = ""
  91. int libraryVersionCode = 0
  92. File versionFile = new File("../../../version.py")
  93. if (versionFile.isFile()) {
  94. def map = [:]
  95. List<String> lines = versionFile.readLines()
  96. for (String line in lines) {
  97. String[] keyValue = line.split("=")
  98. String key = keyValue[0].trim()
  99. String value = keyValue[1].trim().replaceAll("\"", "")
  100. if (requiredKeys.contains(key)) {
  101. if (!value.isEmpty()) {
  102. map[key] = value
  103. }
  104. requiredKeys.remove(key)
  105. }
  106. }
  107. if (requiredKeys.empty) {
  108. libraryVersionName = map.values().join(".")
  109. try {
  110. if (map.containsKey("status")) {
  111. int statusCode = 0
  112. String statusValue = map["status"]
  113. if (statusValue == null) {
  114. statusCode = 0
  115. } else if (statusValue.startsWith("dev")) {
  116. statusCode = 1
  117. } else if (statusValue.startsWith("alpha")) {
  118. statusCode = 2
  119. } else if (statusValue.startsWith("beta")) {
  120. statusCode = 3
  121. } else if (statusValue.startsWith("rc")) {
  122. statusCode = 4
  123. } else if (statusValue.startsWith("stable")) {
  124. statusCode = 5
  125. } else {
  126. statusCode = 0
  127. }
  128. libraryVersionCode = statusCode
  129. }
  130. if (map.containsKey("patch")) {
  131. libraryVersionCode += Integer.parseInt(map["patch"]) * 10
  132. }
  133. if (map.containsKey("minor")) {
  134. libraryVersionCode += (Integer.parseInt(map["minor"]) * 1000)
  135. }
  136. if (map.containsKey("major")) {
  137. libraryVersionCode += (Integer.parseInt(map["major"]) * 100000)
  138. }
  139. } catch (NumberFormatException ignore) {
  140. libraryVersionCode = 1
  141. }
  142. }
  143. }
  144. if (libraryVersionName.isEmpty()) {
  145. // Fallback value in case we're unable to read the file.
  146. libraryVersionName = "custom_build"
  147. }
  148. if (libraryVersionCode == 0) {
  149. libraryVersionCode = 1
  150. }
  151. return [libraryVersionName, libraryVersionCode]
  152. }
  153. ext.getGodotLibraryVersion = { ->
  154. List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
  155. return generateGodotLibraryVersion(requiredKeys)
  156. }
  157. ext.getGodotPublishVersion = { ->
  158. List<String> requiredKeys = ["major", "minor", "patch", "status"]
  159. String versionName = ""
  160. int versionCode = 1
  161. (versionName, versionCode) = generateGodotLibraryVersion(requiredKeys)
  162. if (!versionName.endsWith("stable")) {
  163. versionName += "-SNAPSHOT"
  164. }
  165. return versionName
  166. }
  167. final String VALUE_SEPARATOR_REGEX = "\\|"
  168. // get the list of ABIs the project should be exported to
  169. ext.getExportEnabledABIs = { ->
  170. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : ""
  171. if (enabledABIs == null || enabledABIs.isEmpty()) {
  172. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  173. }
  174. Set<String> exportAbiFilter = []
  175. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  176. if (!abi_name.trim().isEmpty()){
  177. exportAbiFilter.add(abi_name)
  178. }
  179. }
  180. return exportAbiFilter
  181. }
  182. ext.getExportPath = {
  183. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  184. if (exportPath == null || exportPath.isEmpty()) {
  185. exportPath = "."
  186. }
  187. return exportPath
  188. }
  189. ext.getExportFilename = {
  190. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  191. if (exportFilename == null || exportFilename.isEmpty()) {
  192. exportFilename = "godot_android"
  193. }
  194. return exportFilename
  195. }
  196. ext.getExportEdition = {
  197. String exportEdition = project.hasProperty("export_edition") ? project.property("export_edition") : ""
  198. if (exportEdition == null || exportEdition.isEmpty()) {
  199. exportEdition = "standard"
  200. }
  201. return exportEdition
  202. }
  203. ext.getExportBuildType = {
  204. String exportBuildType = project.hasProperty("export_build_type") ? project.property("export_build_type") : ""
  205. if (exportBuildType == null || exportBuildType.isEmpty()) {
  206. exportBuildType = "debug"
  207. }
  208. return exportBuildType
  209. }
  210. ext.getExportFormat = {
  211. String exportFormat = project.hasProperty("export_format") ? project.property("export_format") : ""
  212. if (exportFormat == null || exportFormat.isEmpty()) {
  213. exportFormat = "apk"
  214. }
  215. return exportFormat
  216. }
  217. /**
  218. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  219. * of maven repos.
  220. */
  221. ext.getGodotPluginsMavenRepos = { ->
  222. Set<String> mavenRepos = []
  223. // Retrieve the list of maven repos.
  224. if (project.hasProperty("plugins_maven_repos")) {
  225. String mavenReposProperty = project.property("plugins_maven_repos")
  226. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  227. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  228. mavenRepos += mavenRepoUrl.trim()
  229. }
  230. }
  231. }
  232. return mavenRepos
  233. }
  234. /**
  235. * Parse the project properties for the 'plugins_remote_binaries' property and return
  236. * it for inclusion in the build dependencies.
  237. */
  238. ext.getGodotPluginsRemoteBinaries = { ->
  239. Set<String> remoteDeps = []
  240. // Retrieve the list of remote plugins binaries.
  241. if (project.hasProperty("plugins_remote_binaries")) {
  242. String remoteDepsList = project.property("plugins_remote_binaries")
  243. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  244. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  245. remoteDeps += dep.trim()
  246. }
  247. }
  248. }
  249. return remoteDeps
  250. }
  251. /**
  252. * Parse the project properties for the 'plugins_local_binaries' property and return
  253. * their binaries for inclusion in the build dependencies.
  254. */
  255. ext.getGodotPluginsLocalBinaries = { ->
  256. Set<String> binDeps = []
  257. // Retrieve the list of local plugins binaries.
  258. if (project.hasProperty("plugins_local_binaries")) {
  259. String pluginsList = project.property("plugins_local_binaries")
  260. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  261. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  262. binDeps += plugin.trim()
  263. }
  264. }
  265. }
  266. return binDeps
  267. }
  268. ext.getDebugKeystoreFile = { ->
  269. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  270. if (keystoreFile == null || keystoreFile.isEmpty()) {
  271. keystoreFile = "."
  272. }
  273. return keystoreFile
  274. }
  275. ext.hasCustomDebugKeystore = { ->
  276. File keystoreFile = new File(getDebugKeystoreFile())
  277. return keystoreFile.isFile()
  278. }
  279. ext.getDebugKeystorePassword = { ->
  280. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  281. if (keystorePassword == null || keystorePassword.isEmpty()) {
  282. keystorePassword = "android"
  283. }
  284. return keystorePassword
  285. }
  286. ext.getDebugKeyAlias = { ->
  287. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  288. if (keyAlias == null || keyAlias.isEmpty()) {
  289. keyAlias = "androiddebugkey"
  290. }
  291. return keyAlias
  292. }
  293. ext.getReleaseKeystoreFile = { ->
  294. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  295. if (keystoreFile == null || keystoreFile.isEmpty()) {
  296. keystoreFile = "."
  297. }
  298. return keystoreFile
  299. }
  300. ext.getReleaseKeystorePassword = { ->
  301. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  302. return keystorePassword
  303. }
  304. ext.getReleaseKeyAlias = { ->
  305. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  306. return keyAlias
  307. }
  308. ext.isAndroidStudio = { ->
  309. return project.hasProperty('android.injected.invoked.from.ide')
  310. }
  311. ext.shouldZipAlign = { ->
  312. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  313. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  314. if (isAndroidStudio()) {
  315. zipAlignFlag = "true"
  316. } else {
  317. zipAlignFlag = "false"
  318. }
  319. }
  320. return Boolean.parseBoolean(zipAlignFlag)
  321. }
  322. ext.shouldSign = { ->
  323. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  324. if (signFlag == null || signFlag.isEmpty()) {
  325. if (isAndroidStudio()) {
  326. signFlag = "true"
  327. } else {
  328. signFlag = "false"
  329. }
  330. }
  331. return Boolean.parseBoolean(signFlag)
  332. }
  333. ext.shouldNotStrip = { ->
  334. return isAndroidStudio() || project.hasProperty("doNotStrip")
  335. }
  336. /**
  337. * Whether to use the legacy convention of compressing all .so files in the APK.
  338. *
  339. * For more background, see:
  340. * - https://developer.android.com/build/releases/past-releases/agp-3-6-0-release-notes#extractNativeLibs
  341. * - https://stackoverflow.com/a/44704840
  342. */
  343. ext.shouldUseLegacyPackaging = { ->
  344. String legacyPackagingFlag = project.hasProperty("compress_native_libraries") ? project.property("compress_native_libraries") : ""
  345. if (legacyPackagingFlag != null && !legacyPackagingFlag.isEmpty()) {
  346. return Boolean.parseBoolean(legacyPackagingFlag)
  347. }
  348. if (getExportMinSdkVersion() <= 29) {
  349. // Use legacy packaging for compatibility with device running api <= 29.
  350. // See https://github.com/godotengine/godot/issues/108842 for reference.
  351. return true
  352. }
  353. // Default behavior for minSdk > 29.
  354. return false
  355. }
  356. ext.getAddonsDirectory = { ->
  357. String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : ""
  358. return addonsDirectory
  359. }