build.gradle 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. boolean toolsFlag = flavorName == "editor"
  83. def buildType = variant.buildType.name
  84. if (buildType == null || buildType == "" || !supportedTargetsMap.containsKey(buildType)) {
  85. throw new GradleException("Invalid build type: $buildType")
  86. }
  87. def sconsTarget = supportedTargetsMap[buildType]
  88. if (sconsTarget == null || sconsTarget == "") {
  89. throw new GradleException("Invalid scons target: $sconsTarget")
  90. }
  91. // Update the name of the generated library
  92. def outputSuffix = "${buildType}.aar"
  93. if (toolsFlag) {
  94. outputSuffix = "tools.$outputSuffix"
  95. }
  96. variant.outputs.all { output ->
  97. output.outputFileName = "godot-lib.${outputSuffix}"
  98. }
  99. // Find scons' executable path
  100. File sconsExecutableFile = null
  101. def sconsName = "scons"
  102. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  103. ? [".bat", ".cmd", ".ps1", ".exe"]
  104. : [""])
  105. logger.lifecycle("Looking for $sconsName executable path")
  106. for (ext in sconsExts) {
  107. String sconsNameExt = sconsName + ext
  108. logger.lifecycle("Checking $sconsNameExt")
  109. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  110. if (sconsExecutableFile != null) {
  111. // We're done!
  112. break
  113. }
  114. // Check all the options in path
  115. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  116. if (!allOptions.isEmpty()) {
  117. // Pick the first option and we're done!
  118. sconsExecutableFile = allOptions.get(0)
  119. break
  120. }
  121. }
  122. if (sconsExecutableFile == null) {
  123. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  124. } else {
  125. logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  126. }
  127. for (String selectedAbi : selectedAbis) {
  128. if (!supportedAbis.contains(selectedAbi)) {
  129. throw new GradleException("Invalid selected abi: $selectedAbi")
  130. }
  131. // Creating gradle task to generate the native libraries for the selected abi.
  132. def taskName = getSconsTaskName(flavorName, buildType, selectedAbi)
  133. tasks.create(name: taskName, type: Exec) {
  134. executable sconsExecutableFile.absolutePath
  135. args "--directory=${pathToRootDir}", "platform=android", "tools=${toolsFlag}", "target=${sconsTarget}", "android_arch=${selectedAbi}", "-j" + Runtime.runtime.availableProcessors()
  136. }
  137. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  138. tasks["merge${flavorName.capitalize()}${buildType.capitalize()}JniLibFolders"].dependsOn taskName
  139. }
  140. }
  141. publishing {
  142. singleVariant("templateRelease") {
  143. withSourcesJar()
  144. withJavadocJar()
  145. }
  146. }
  147. }