build.gradle 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. apply plugin: 'io.github.gradle-nexus.publish-plugin'
  2. apply from: 'app/config.gradle'
  3. apply from: 'scripts/publish-root.gradle'
  4. buildscript {
  5. apply from: 'app/config.gradle'
  6. repositories {
  7. google()
  8. mavenCentral()
  9. maven { url "https://plugins.gradle.org/m2/" }
  10. }
  11. dependencies {
  12. classpath libraries.androidGradlePlugin
  13. classpath libraries.kotlinGradlePlugin
  14. classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
  15. }
  16. }
  17. allprojects {
  18. repositories {
  19. google()
  20. mavenCentral()
  21. }
  22. }
  23. ext {
  24. supportedAbis = ["armv7", "arm64v8", "x86", "x86_64"]
  25. supportedTargets = ["release", "debug"]
  26. // Used by gradle to specify which architecture to build for by default when running `./gradlew build`.
  27. // This command is usually used by Android Studio.
  28. // If building manually on the command line, it's recommended to use the
  29. // `./gradlew generateGodotTemplates` build command instead after running the `scons` command.
  30. // The defaultAbi must be one of the {supportedAbis} values.
  31. defaultAbi = "arm64v8"
  32. }
  33. def rootDir = "../../.."
  34. def binDir = "$rootDir/bin/"
  35. def getSconsTaskName(String buildType) {
  36. return "compileGodotNativeLibs" + buildType.capitalize()
  37. }
  38. /**
  39. * Copy the generated 'android_debug.apk' binary template into the Godot bin directory.
  40. * Depends on the app build task to ensure the binary is generated prior to copying.
  41. */
  42. task copyDebugBinaryToBin(type: Copy) {
  43. dependsOn ':app:assembleDebug'
  44. from('app/build/outputs/apk/debug')
  45. into(binDir)
  46. include('android_debug.apk')
  47. }
  48. /**
  49. * Copy the generated 'android_release.apk' binary template into the Godot bin directory.
  50. * Depends on the app build task to ensure the binary is generated prior to copying.
  51. */
  52. task copyReleaseBinaryToBin(type: Copy) {
  53. dependsOn ':app:assembleRelease'
  54. from('app/build/outputs/apk/release')
  55. into(binDir)
  56. include('android_release.apk')
  57. }
  58. /**
  59. * Copy the Godot android library archive debug file into the app module debug libs directory.
  60. * Depends on the library build task to ensure the AAR file is generated prior to copying.
  61. */
  62. task copyDebugAARToAppModule(type: Copy) {
  63. dependsOn ':lib:assembleDebug'
  64. from('lib/build/outputs/aar')
  65. into('app/libs/debug')
  66. include('godot-lib.debug.aar')
  67. }
  68. /**
  69. * Copy the Godot android library archive debug file into the root bin directory.
  70. * Depends on the library build task to ensure the AAR file is generated prior to copying.
  71. */
  72. task copyDebugAARToBin(type: Copy) {
  73. dependsOn ':lib:assembleDebug'
  74. from('lib/build/outputs/aar')
  75. into(binDir)
  76. include('godot-lib.debug.aar')
  77. }
  78. /**
  79. * Copy the Godot android library archive release file into the app module release libs directory.
  80. * Depends on the library build task to ensure the AAR file is generated prior to copying.
  81. */
  82. task copyReleaseAARToAppModule(type: Copy) {
  83. dependsOn ':lib:assembleRelease'
  84. from('lib/build/outputs/aar')
  85. into('app/libs/release')
  86. include('godot-lib.release.aar')
  87. }
  88. /**
  89. * Copy the Godot android library archive release file into the root bin directory.
  90. * Depends on the library build task to ensure the AAR file is generated prior to copying.
  91. */
  92. task copyReleaseAARToBin(type: Copy) {
  93. dependsOn ':lib:assembleRelease'
  94. from('lib/build/outputs/aar')
  95. into(binDir)
  96. include('godot-lib.release.aar')
  97. }
  98. /**
  99. * Generate Godot custom build template by zipping the source files from the app directory, as well
  100. * as the AAR files generated by 'copyDebugAAR' and 'copyReleaseAAR'.
  101. * The zip file also includes some gradle tools to allow building of the custom build.
  102. */
  103. task zipCustomBuild(type: Zip) {
  104. onlyIf { generateGodotTemplates.state.executed || generateDevTemplate.state.executed }
  105. doFirst {
  106. logger.lifecycle("Generating Godot custom build template")
  107. }
  108. from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradlew', 'gradlew.bat', 'gradle/**']))
  109. include '**/*'
  110. archiveFileName = 'android_source.zip'
  111. destinationDirectory = file(binDir)
  112. }
  113. def templateExcludedBuildTask() {
  114. // We exclude these gradle tasks so we can run the scons command manually.
  115. def excludedTasks = []
  116. for (String buildType : supportedTargets) {
  117. excludedTasks += ":lib:" + getSconsTaskName(buildType)
  118. }
  119. return excludedTasks
  120. }
  121. def templateBuildTasks() {
  122. def tasks = []
  123. // Only build the apks and aar files for which we have native shared libraries.
  124. for (String target : supportedTargets) {
  125. File targetLibs = new File("lib/libs/" + target)
  126. if (targetLibs != null
  127. && targetLibs.isDirectory()
  128. && targetLibs.listFiles() != null
  129. && targetLibs.listFiles().length > 0) {
  130. String capitalizedTarget = target.capitalize()
  131. // Copy the generated aar library files to the custom build directory.
  132. tasks += "copy" + capitalizedTarget + "AARToAppModule"
  133. // Copy the generated aar library files to the bin directory.
  134. tasks += "copy" + capitalizedTarget + "AARToBin"
  135. // Copy the prebuilt binary templates to the bin directory.
  136. tasks += "copy" + capitalizedTarget + "BinaryToBin"
  137. } else {
  138. logger.lifecycle("No native shared libs for target $target. Skipping build.")
  139. }
  140. }
  141. return tasks
  142. }
  143. /**
  144. * Master task used to coordinate the tasks defined above to generate the set of Godot templates.
  145. */
  146. task generateGodotTemplates {
  147. gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
  148. dependsOn = templateBuildTasks()
  149. finalizedBy 'zipCustomBuild'
  150. }
  151. /**
  152. * Generates the same output as generateGodotTemplates but with dev symbols
  153. */
  154. task generateDevTemplate {
  155. // add parameter to set symbols to true
  156. gradle.startParameter.projectProperties += [doNotStrip: true]
  157. gradle.startParameter.excludedTaskNames += templateExcludedBuildTask()
  158. dependsOn = templateBuildTasks()
  159. finalizedBy 'zipCustomBuild'
  160. }
  161. /**
  162. * Clean the generated artifacts.
  163. */
  164. task cleanGodotTemplates(type: Delete) {
  165. // Delete the generated native libs
  166. delete("lib/libs")
  167. // Delete the library generated AAR files
  168. delete("lib/build/outputs/aar")
  169. // Delete the app libs directory contents
  170. delete("app/libs")
  171. // Delete the generated binary apks
  172. delete("app/build/outputs/apk")
  173. // Delete the Godot templates in the Godot bin directory
  174. delete("$binDir/android_debug.apk")
  175. delete("$binDir/android_release.apk")
  176. delete("$binDir/android_source.zip")
  177. delete("$binDir/godot-lib.debug.aar")
  178. delete("$binDir/godot-lib.release.aar")
  179. finalizedBy getTasksByName("clean", true)
  180. }