build.gradle 5.9 KB

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