build.gradle 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. plugins {
  2. id 'com.android.library'
  3. id 'org.jetbrains.kotlin.android'
  4. }
  5. ext {
  6. DEBUG_PUBLISH_ARTIFACT_ID = 'godot-debug'
  7. PUBLISH_ARTIFACT_ID = 'godot'
  8. TOOLS_PUBLISH_ARTIFACT_ID = 'godot-tools'
  9. }
  10. apply from: "../scripts/publish-module.gradle"
  11. dependencies {
  12. implementation "androidx.fragment:fragment:$versions.fragmentVersion"
  13. implementation 'androidx.documentfile:documentfile:1.1.0'
  14. testImplementation "junit:junit:4.13.2"
  15. }
  16. def pathToRootDir = "../../../../"
  17. android {
  18. compileSdkVersion versions.compileSdk
  19. buildToolsVersion versions.buildTools
  20. ndkVersion versions.ndkVersion
  21. defaultConfig {
  22. minSdkVersion versions.minSdk
  23. targetSdkVersion versions.targetSdk
  24. manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersionName()]
  25. }
  26. namespace = "org.godotengine.godot"
  27. compileOptions {
  28. sourceCompatibility versions.javaVersion
  29. targetCompatibility versions.javaVersion
  30. }
  31. kotlinOptions {
  32. jvmTarget = versions.javaVersion
  33. }
  34. buildFeatures {
  35. aidl = true
  36. buildConfig = true
  37. }
  38. buildTypes {
  39. dev {
  40. initWith debug
  41. }
  42. }
  43. flavorDimensions = ["products"]
  44. productFlavors {
  45. editor {}
  46. template {}
  47. }
  48. lintOptions {
  49. abortOnError false
  50. disable 'MissingTranslation', 'UnusedResources'
  51. }
  52. packagingOptions {
  53. exclude 'META-INF/LICENSE'
  54. exclude 'META-INF/NOTICE'
  55. // Debug symbols are kept for development within Android Studio.
  56. if (shouldNotStrip()) {
  57. jniLibs {
  58. keepDebugSymbols += '**/*.so'
  59. }
  60. }
  61. }
  62. sourceSets {
  63. debug.jniLibs.srcDirs = ['libs/debug']
  64. dev.jniLibs.srcDirs = ['libs/dev']
  65. release.jniLibs.srcDirs = ['libs/release']
  66. // Editor jni library
  67. editorRelease.jniLibs.srcDirs = ['libs/tools/release']
  68. editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
  69. editorDev.jniLibs.srcDirs = ['libs/tools/dev']
  70. }
  71. libraryVariants.all { variant ->
  72. def flavorName = variant.getFlavorName()
  73. if (flavorName == null || flavorName == "") {
  74. throw new GradleException("Invalid product flavor: $flavorName")
  75. }
  76. def buildType = variant.buildType.name
  77. if (buildType == null || buildType == "" || !supportedFlavorsBuildTypes[flavorName].contains(buildType)) {
  78. throw new GradleException("Invalid build type: $buildType")
  79. }
  80. boolean devBuild = buildType == "dev"
  81. boolean debugSymbols = devBuild
  82. boolean runTests = devBuild
  83. boolean storeRelease = buildType == "release"
  84. boolean productionBuild = storeRelease
  85. def sconsTarget = flavorName
  86. if (sconsTarget == "template") {
  87. // Tests are not supported on template builds
  88. runTests = false
  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.debug("Looking for $sconsName executable path")
  115. for (ext in sconsExts) {
  116. String sconsNameExt = sconsName + ext
  117. logger.debug("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.debug("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", "store_release=${storeRelease}", "production=${productionBuild}", "dev_mode=${devBuild}", "dev_build=${devBuild}", "debug_symbols=${debugSymbols}", "tests=${runTests}", "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. publishing {
  151. singleVariant("templateDebug") {
  152. withSourcesJar()
  153. withJavadocJar()
  154. }
  155. singleVariant("templateRelease") {
  156. withSourcesJar()
  157. withJavadocJar()
  158. }
  159. singleVariant("editorRelease") {
  160. withSourcesJar()
  161. withJavadocJar()
  162. }
  163. }
  164. }