build.gradle 5.5 KB

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