build.gradle 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. editorRelease.jniLibs.srcDirs = ['libs/tools/release']
  66. editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
  67. editorDev.jniLibs.srcDirs = ['libs/tools/dev']
  68. }
  69. libraryVariants.all { variant ->
  70. def flavorName = variant.getFlavorName()
  71. if (flavorName == null || flavorName == "") {
  72. throw new GradleException("Invalid product flavor: $flavorName")
  73. }
  74. def buildType = variant.buildType.name
  75. if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) {
  76. throw new GradleException("Invalid build type: $buildType")
  77. }
  78. boolean devBuild = buildType == "dev"
  79. boolean runTests = devBuild
  80. boolean productionBuild = !devBuild
  81. boolean storeRelease = buildType == "release"
  82. def sconsTarget = flavorName
  83. if (sconsTarget == "template") {
  84. // Tests are not supported on template builds
  85. runTests = false
  86. switch (buildType) {
  87. case "release":
  88. sconsTarget += "_release"
  89. break
  90. case "debug":
  91. case "dev":
  92. default:
  93. sconsTarget += "_debug"
  94. break;
  95. }
  96. }
  97. // Update the name of the generated library
  98. def outputSuffix = "${sconsTarget}"
  99. if (devBuild) {
  100. outputSuffix = "${outputSuffix}.dev"
  101. }
  102. variant.outputs.all { output ->
  103. output.outputFileName = "godot-lib.${outputSuffix}.aar"
  104. }
  105. // Find scons' executable path
  106. File sconsExecutableFile = null
  107. def sconsName = "scons"
  108. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  109. ? [".bat", ".cmd", ".ps1", ".exe"]
  110. : [""])
  111. logger.debug("Looking for $sconsName executable path")
  112. for (ext in sconsExts) {
  113. String sconsNameExt = sconsName + ext
  114. logger.debug("Checking $sconsNameExt")
  115. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  116. if (sconsExecutableFile != null) {
  117. // We're done!
  118. break
  119. }
  120. // Check all the options in path
  121. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  122. if (!allOptions.isEmpty()) {
  123. // Pick the first option and we're done!
  124. sconsExecutableFile = allOptions.get(0)
  125. break
  126. }
  127. }
  128. if (sconsExecutableFile == null) {
  129. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  130. } else {
  131. logger.debug("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  132. }
  133. for (String selectedAbi : selectedAbis) {
  134. if (!supportedAbis.contains(selectedAbi)) {
  135. throw new GradleException("Invalid selected abi: $selectedAbi")
  136. }
  137. // Creating gradle task to generate the native libraries for the selected abi.
  138. def taskName = getSconsTaskName(flavorName, buildType, selectedAbi)
  139. tasks.create(name: taskName, type: Exec) {
  140. executable sconsExecutableFile.absolutePath
  141. args "--directory=${pathToRootDir}", "platform=android", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${devBuild}", "dev_build=${devBuild}", "tests=${runTests}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors()
  142. }
  143. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  144. tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName
  145. }
  146. }
  147. publishing {
  148. singleVariant("templateRelease") {
  149. withSourcesJar()
  150. withJavadocJar()
  151. }
  152. }
  153. }