2
0

build.gradle 6.3 KB

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