build.gradle 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. plugins {
  2. id 'com.android.library'
  3. id 'org.jetbrains.kotlin.android'
  4. }
  5. ext {
  6. PUBLISH_ARTIFACT_ID = 'godot'
  7. }
  8. apply from: "../scripts/publish-module.gradle"
  9. dependencies {
  10. implementation libraries.kotlinStdLib
  11. implementation libraries.androidxFragment
  12. }
  13. def pathToRootDir = "../../../../"
  14. android {
  15. compileSdkVersion versions.compileSdk
  16. buildToolsVersion versions.buildTools
  17. ndkVersion versions.ndkVersion
  18. defaultConfig {
  19. minSdkVersion versions.minSdk
  20. targetSdkVersion versions.targetSdk
  21. manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()]
  22. }
  23. namespace = "org.godotengine.godot"
  24. compileOptions {
  25. sourceCompatibility versions.javaVersion
  26. targetCompatibility versions.javaVersion
  27. }
  28. kotlinOptions {
  29. jvmTarget = versions.javaVersion
  30. }
  31. buildTypes {
  32. dev {
  33. initWith debug
  34. }
  35. }
  36. flavorDimensions "products"
  37. productFlavors {
  38. editor {}
  39. template {}
  40. }
  41. lintOptions {
  42. abortOnError false
  43. disable 'MissingTranslation', 'UnusedResources'
  44. }
  45. packagingOptions {
  46. exclude 'META-INF/LICENSE'
  47. exclude 'META-INF/NOTICE'
  48. // 'doNotStrip' is enabled for development within Android Studio
  49. if (shouldNotStrip()) {
  50. doNotStrip '**/*.so'
  51. }
  52. }
  53. sourceSets {
  54. main {
  55. manifest.srcFile 'AndroidManifest.xml'
  56. java.srcDirs = ['src']
  57. res.srcDirs = ['res']
  58. aidl.srcDirs = ['aidl']
  59. assets.srcDirs = ['assets']
  60. }
  61. debug.jniLibs.srcDirs = ['libs/debug']
  62. dev.jniLibs.srcDirs = ['libs/dev']
  63. release.jniLibs.srcDirs = ['libs/release']
  64. // Editor jni library
  65. editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
  66. editorDev.jniLibs.srcDirs = ['libs/tools/dev']
  67. }
  68. // Disable 'editorRelease'.
  69. // The editor can't be used with target=release as debugging tools are then not
  70. // included, and it would crash on errors instead of reporting them.
  71. variantFilter { variant ->
  72. if (variant.name == "editorRelease") {
  73. setIgnore(true)
  74. }
  75. }
  76. libraryVariants.all { variant ->
  77. def flavorName = variant.getFlavorName()
  78. if (flavorName == null || flavorName == "") {
  79. throw new GradleException("Invalid product flavor: $flavorName")
  80. }
  81. def buildType = variant.buildType.name
  82. if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) {
  83. throw new GradleException("Invalid build type: $buildType")
  84. }
  85. boolean devBuild = buildType == "dev"
  86. def sconsTarget = flavorName
  87. if (sconsTarget == "template") {
  88. switch (buildType) {
  89. case "release":
  90. sconsTarget += "_release"
  91. break
  92. case "debug":
  93. case "dev":
  94. default:
  95. sconsTarget += "_debug"
  96. break;
  97. }
  98. }
  99. // Update the name of the generated library
  100. def outputSuffix = "${sconsTarget}"
  101. if (devBuild) {
  102. outputSuffix = "${outputSuffix}.dev"
  103. }
  104. variant.outputs.all { output ->
  105. output.outputFileName = "godot-lib.${outputSuffix}.aar"
  106. }
  107. // Find scons' executable path
  108. File sconsExecutableFile = null
  109. def sconsName = "scons"
  110. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  111. ? [".bat", ".cmd", ".ps1", ".exe"]
  112. : [""])
  113. logger.lifecycle("Looking for $sconsName executable path")
  114. for (ext in sconsExts) {
  115. String sconsNameExt = sconsName + ext
  116. logger.lifecycle("Checking $sconsNameExt")
  117. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  118. if (sconsExecutableFile != null) {
  119. // We're done!
  120. break
  121. }
  122. // Check all the options in path
  123. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  124. if (!allOptions.isEmpty()) {
  125. // Pick the first option and we're done!
  126. sconsExecutableFile = allOptions.get(0)
  127. break
  128. }
  129. }
  130. if (sconsExecutableFile == null) {
  131. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  132. } else {
  133. logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  134. }
  135. for (String selectedAbi : selectedAbis) {
  136. if (!supportedAbis.contains(selectedAbi)) {
  137. throw new GradleException("Invalid selected abi: $selectedAbi")
  138. }
  139. // Creating gradle task to generate the native libraries for the selected abi.
  140. def taskName = getSconsTaskName(flavorName, buildType, selectedAbi)
  141. tasks.create(name: taskName, type: Exec) {
  142. executable sconsExecutableFile.absolutePath
  143. args "--directory=${pathToRootDir}", "platform=android", "dev_mode=${devBuild}", "dev_build=${devBuild}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors()
  144. }
  145. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  146. tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName
  147. }
  148. }
  149. publishing {
  150. singleVariant("templateRelease") {
  151. withSourcesJar()
  152. withJavadocJar()
  153. }
  154. }
  155. }