build.gradle 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "androidx.fragment:fragment:$versions.fragmentVersion"
  11. testImplementation "junit:junit:4.13.2"
  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. buildFeatures {
  32. aidl = true
  33. buildConfig = true
  34. }
  35. buildTypes {
  36. dev {
  37. initWith debug
  38. }
  39. }
  40. flavorDimensions = ["products"]
  41. productFlavors {
  42. editor {}
  43. template {}
  44. }
  45. lintOptions {
  46. abortOnError false
  47. disable 'MissingTranslation', 'UnusedResources'
  48. }
  49. packagingOptions {
  50. exclude 'META-INF/LICENSE'
  51. exclude 'META-INF/NOTICE'
  52. // 'doNotStrip' is enabled for development within Android Studio
  53. if (shouldNotStrip()) {
  54. doNotStrip '**/*.so'
  55. }
  56. }
  57. sourceSets {
  58. main {
  59. manifest.srcFile 'AndroidManifest.xml'
  60. java.srcDirs = ['src']
  61. test.java.srcDirs = ['srcTest/java']
  62. res.srcDirs = ['res']
  63. aidl.srcDirs = ['aidl']
  64. assets.srcDirs = ['assets']
  65. }
  66. debug.jniLibs.srcDirs = ['libs/debug']
  67. dev.jniLibs.srcDirs = ['libs/dev']
  68. release.jniLibs.srcDirs = ['libs/release']
  69. // Editor jni library
  70. editorRelease.jniLibs.srcDirs = ['libs/tools/release']
  71. editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
  72. editorDev.jniLibs.srcDirs = ['libs/tools/dev']
  73. }
  74. libraryVariants.all { variant ->
  75. def flavorName = variant.getFlavorName()
  76. if (flavorName == null || flavorName == "") {
  77. throw new GradleException("Invalid product flavor: $flavorName")
  78. }
  79. def buildType = variant.buildType.name
  80. if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) {
  81. throw new GradleException("Invalid build type: $buildType")
  82. }
  83. boolean devBuild = buildType == "dev"
  84. boolean debugSymbols = devBuild
  85. boolean runTests = devBuild
  86. boolean storeRelease = buildType == "release"
  87. boolean productionBuild = storeRelease
  88. def sconsTarget = flavorName
  89. if (sconsTarget == "template") {
  90. // Tests are not supported on template builds
  91. runTests = false
  92. switch (buildType) {
  93. case "release":
  94. sconsTarget += "_release"
  95. break
  96. case "debug":
  97. case "dev":
  98. default:
  99. sconsTarget += "_debug"
  100. break
  101. }
  102. }
  103. // Update the name of the generated library
  104. def outputSuffix = "${sconsTarget}"
  105. if (devBuild) {
  106. outputSuffix = "${outputSuffix}.dev"
  107. }
  108. variant.outputs.all { output ->
  109. output.outputFileName = "godot-lib.${outputSuffix}.aar"
  110. }
  111. // Find scons' executable path
  112. File sconsExecutableFile = null
  113. def sconsName = "scons"
  114. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  115. ? [".bat", ".cmd", ".ps1", ".exe"]
  116. : [""])
  117. logger.debug("Looking for $sconsName executable path")
  118. for (ext in sconsExts) {
  119. String sconsNameExt = sconsName + ext
  120. logger.debug("Checking $sconsNameExt")
  121. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  122. if (sconsExecutableFile != null) {
  123. // We're done!
  124. break
  125. }
  126. // Check all the options in path
  127. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  128. if (!allOptions.isEmpty()) {
  129. // Pick the first option and we're done!
  130. sconsExecutableFile = allOptions.get(0)
  131. break
  132. }
  133. }
  134. if (sconsExecutableFile == null) {
  135. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  136. } else {
  137. logger.debug("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  138. }
  139. for (String selectedAbi : selectedAbis) {
  140. if (!supportedAbis.contains(selectedAbi)) {
  141. throw new GradleException("Invalid selected abi: $selectedAbi")
  142. }
  143. // Creating gradle task to generate the native libraries for the selected abi.
  144. def taskName = getSconsTaskName(flavorName, buildType, selectedAbi)
  145. tasks.create(name: taskName, type: Exec) {
  146. executable sconsExecutableFile.absolutePath
  147. args "--directory=${pathToRootDir}", "platform=android", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${devBuild}", "dev_build=${devBuild}", "debug_symbols=${debugSymbols}", "tests=${runTests}", "target=${sconsTarget}", "arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors()
  148. }
  149. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  150. tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName
  151. }
  152. }
  153. publishing {
  154. singleVariant("templateRelease") {
  155. withSourcesJar()
  156. withJavadocJar()
  157. }
  158. }
  159. }