config.gradle 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ext.versions = [
  2. androidGradlePlugin: '7.0.3',
  3. compileSdk : 30,
  4. minSdk : 19, // Also update 'platform/android/java/lib/AndroidManifest.xml#minSdkVersion' & 'platform/android/export/export_plugin.cpp#DEFAULT_MIN_SDK_VERSION'
  5. targetSdk : 30, // Also update 'platform/android/java/lib/AndroidManifest.xml#targetSdkVersion' & 'platform/android/export/export_plugin.cpp#DEFAULT_TARGET_SDK_VERSION'
  6. buildTools : '30.0.3',
  7. kotlinVersion : '1.6.10',
  8. fragmentVersion : '1.3.6',
  9. javaVersion : 11,
  10. ndkVersion : '21.4.7075529' // Also update 'platform/android/detect.py#get_project_ndk_version()' when this is updated.
  11. ]
  12. ext.libraries = [
  13. androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
  14. kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
  15. kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlinVersion",
  16. androidxFragment : "androidx.fragment:fragment:$versions.fragmentVersion",
  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.getGodotEditorVersion = { ->
  68. String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
  69. if (editorVersion == null || editorVersion.isEmpty()) {
  70. // Try the library version first
  71. editorVersion = getGodotLibraryVersion()
  72. if (editorVersion.isEmpty()) {
  73. // Fallback value.
  74. editorVersion = "custom_build"
  75. }
  76. }
  77. return editorVersion
  78. }
  79. ext.generateGodotLibraryVersion = { List<String> requiredKeys ->
  80. // Attempt to read the version from the `version.py` file.
  81. String libraryVersion = ""
  82. File versionFile = new File("../../../version.py")
  83. if (versionFile.isFile()) {
  84. def map = [:]
  85. List<String> lines = versionFile.readLines()
  86. for (String line in lines) {
  87. String[] keyValue = line.split("=")
  88. String key = keyValue[0].trim()
  89. String value = keyValue[1].trim().replaceAll("\"", "")
  90. if (requiredKeys.contains(key)) {
  91. if (!value.isEmpty()) {
  92. map[key] = value
  93. }
  94. requiredKeys.remove(key)
  95. }
  96. }
  97. if (requiredKeys.empty) {
  98. libraryVersion = map.values().join(".")
  99. }
  100. }
  101. if (libraryVersion.isEmpty()) {
  102. // Fallback value in case we're unable to read the file.
  103. libraryVersion = "custom_build"
  104. }
  105. return libraryVersion
  106. }
  107. ext.getGodotLibraryVersion = { ->
  108. List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
  109. return generateGodotLibraryVersion(requiredKeys)
  110. }
  111. ext.getGodotPublishVersion = { ->
  112. List<String> requiredKeys = ["major", "minor", "patch", "status"]
  113. return generateGodotLibraryVersion(requiredKeys)
  114. }
  115. final String VALUE_SEPARATOR_REGEX = "\\|"
  116. // get the list of ABIs the project should be exported to
  117. ext.getExportEnabledABIs = { ->
  118. String enabledABIs = project.hasProperty("export_enabled_abis") ? project.property("export_enabled_abis") : "";
  119. if (enabledABIs == null || enabledABIs.isEmpty()) {
  120. enabledABIs = "armeabi-v7a|arm64-v8a|x86|x86_64|"
  121. }
  122. Set<String> exportAbiFilter = [];
  123. for (String abi_name : enabledABIs.split(VALUE_SEPARATOR_REGEX)) {
  124. if (!abi_name.trim().isEmpty()){
  125. exportAbiFilter.add(abi_name);
  126. }
  127. }
  128. return exportAbiFilter;
  129. }
  130. ext.getExportPath = {
  131. String exportPath = project.hasProperty("export_path") ? project.property("export_path") : ""
  132. if (exportPath == null || exportPath.isEmpty()) {
  133. exportPath = "."
  134. }
  135. return exportPath
  136. }
  137. ext.getExportFilename = {
  138. String exportFilename = project.hasProperty("export_filename") ? project.property("export_filename") : ""
  139. if (exportFilename == null || exportFilename.isEmpty()) {
  140. exportFilename = "godot_android"
  141. }
  142. return exportFilename
  143. }
  144. /**
  145. * Parse the project properties for the 'plugins_maven_repos' property and return the list
  146. * of maven repos.
  147. */
  148. ext.getGodotPluginsMavenRepos = { ->
  149. Set<String> mavenRepos = []
  150. // Retrieve the list of maven repos.
  151. if (project.hasProperty("plugins_maven_repos")) {
  152. String mavenReposProperty = project.property("plugins_maven_repos")
  153. if (mavenReposProperty != null && !mavenReposProperty.trim().isEmpty()) {
  154. for (String mavenRepoUrl : mavenReposProperty.split(VALUE_SEPARATOR_REGEX)) {
  155. mavenRepos += mavenRepoUrl.trim()
  156. }
  157. }
  158. }
  159. return mavenRepos
  160. }
  161. /**
  162. * Parse the project properties for the 'plugins_remote_binaries' property and return
  163. * it for inclusion in the build dependencies.
  164. */
  165. ext.getGodotPluginsRemoteBinaries = { ->
  166. Set<String> remoteDeps = []
  167. // Retrieve the list of remote plugins binaries.
  168. if (project.hasProperty("plugins_remote_binaries")) {
  169. String remoteDepsList = project.property("plugins_remote_binaries")
  170. if (remoteDepsList != null && !remoteDepsList.trim().isEmpty()) {
  171. for (String dep: remoteDepsList.split(VALUE_SEPARATOR_REGEX)) {
  172. remoteDeps += dep.trim()
  173. }
  174. }
  175. }
  176. return remoteDeps
  177. }
  178. /**
  179. * Parse the project properties for the 'plugins_local_binaries' property and return
  180. * their binaries for inclusion in the build dependencies.
  181. */
  182. ext.getGodotPluginsLocalBinaries = { ->
  183. Set<String> binDeps = []
  184. // Retrieve the list of local plugins binaries.
  185. if (project.hasProperty("plugins_local_binaries")) {
  186. String pluginsList = project.property("plugins_local_binaries")
  187. if (pluginsList != null && !pluginsList.trim().isEmpty()) {
  188. for (String plugin : pluginsList.split(VALUE_SEPARATOR_REGEX)) {
  189. binDeps += plugin.trim()
  190. }
  191. }
  192. }
  193. return binDeps
  194. }
  195. ext.getDebugKeystoreFile = { ->
  196. String keystoreFile = project.hasProperty("debug_keystore_file") ? project.property("debug_keystore_file") : ""
  197. if (keystoreFile == null || keystoreFile.isEmpty()) {
  198. keystoreFile = "."
  199. }
  200. return keystoreFile
  201. }
  202. ext.hasCustomDebugKeystore = { ->
  203. File keystoreFile = new File(getDebugKeystoreFile())
  204. return keystoreFile.isFile()
  205. }
  206. ext.getDebugKeystorePassword = { ->
  207. String keystorePassword = project.hasProperty("debug_keystore_password") ? project.property("debug_keystore_password") : ""
  208. if (keystorePassword == null || keystorePassword.isEmpty()) {
  209. keystorePassword = "android"
  210. }
  211. return keystorePassword
  212. }
  213. ext.getDebugKeyAlias = { ->
  214. String keyAlias = project.hasProperty("debug_keystore_alias") ? project.property("debug_keystore_alias") : ""
  215. if (keyAlias == null || keyAlias.isEmpty()) {
  216. keyAlias = "androiddebugkey"
  217. }
  218. return keyAlias
  219. }
  220. ext.getReleaseKeystoreFile = { ->
  221. String keystoreFile = project.hasProperty("release_keystore_file") ? project.property("release_keystore_file") : ""
  222. if (keystoreFile == null || keystoreFile.isEmpty()) {
  223. keystoreFile = "."
  224. }
  225. return keystoreFile
  226. }
  227. ext.getReleaseKeystorePassword = { ->
  228. String keystorePassword = project.hasProperty("release_keystore_password") ? project.property("release_keystore_password") : ""
  229. return keystorePassword
  230. }
  231. ext.getReleaseKeyAlias = { ->
  232. String keyAlias = project.hasProperty("release_keystore_alias") ? project.property("release_keystore_alias") : ""
  233. return keyAlias
  234. }
  235. ext.isAndroidStudio = { ->
  236. def sysProps = System.getProperties()
  237. return sysProps != null && sysProps['idea.platform.prefix'] != null
  238. }
  239. ext.shouldZipAlign = { ->
  240. String zipAlignFlag = project.hasProperty("perform_zipalign") ? project.property("perform_zipalign") : ""
  241. if (zipAlignFlag == null || zipAlignFlag.isEmpty()) {
  242. if (isAndroidStudio()) {
  243. zipAlignFlag = "true"
  244. } else {
  245. zipAlignFlag = "false"
  246. }
  247. }
  248. return Boolean.parseBoolean(zipAlignFlag)
  249. }
  250. ext.shouldSign = { ->
  251. String signFlag = project.hasProperty("perform_signing") ? project.property("perform_signing") : ""
  252. if (signFlag == null || signFlag.isEmpty()) {
  253. if (isAndroidStudio()) {
  254. signFlag = "true"
  255. } else {
  256. signFlag = "false"
  257. }
  258. }
  259. return Boolean.parseBoolean(signFlag)
  260. }
  261. ext.shouldNotStrip = { ->
  262. return isAndroidStudio() || project.hasProperty("doNotStrip")
  263. }