build.gradle 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. apply plugin: 'com.android.library'
  2. apply plugin: 'kotlin-android'
  3. dependencies {
  4. implementation libraries.supportCoreUtils
  5. implementation libraries.kotlinStdLib
  6. implementation libraries.v4Support
  7. }
  8. def pathToRootDir = "../../../../"
  9. android {
  10. compileSdkVersion versions.compileSdk
  11. buildToolsVersion versions.buildTools
  12. ndkVersion versions.ndkVersion
  13. defaultConfig {
  14. minSdkVersion versions.minSdk
  15. targetSdkVersion versions.targetSdk
  16. manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersion()]
  17. }
  18. compileOptions {
  19. sourceCompatibility versions.javaVersion
  20. targetCompatibility versions.javaVersion
  21. }
  22. lintOptions {
  23. abortOnError false
  24. disable 'MissingTranslation', 'UnusedResources'
  25. }
  26. packagingOptions {
  27. exclude 'META-INF/LICENSE'
  28. exclude 'META-INF/NOTICE'
  29. // 'doNotStrip' is enabled for development within Android Studio
  30. if (shouldNotStrip()) {
  31. doNotStrip '**/*.so'
  32. }
  33. }
  34. sourceSets {
  35. main {
  36. manifest.srcFile 'AndroidManifest.xml'
  37. java.srcDirs = ['src']
  38. res.srcDirs = ['res']
  39. aidl.srcDirs = ['aidl']
  40. assets.srcDirs = ['assets']
  41. }
  42. debug.jniLibs.srcDirs = ['libs/debug']
  43. release.jniLibs.srcDirs = ['libs/release']
  44. }
  45. libraryVariants.all { variant ->
  46. variant.outputs.all { output ->
  47. output.outputFileName = "godot-lib.${variant.name}.aar"
  48. }
  49. def buildType = variant.buildType.name.capitalize()
  50. def releaseTarget = buildType.toLowerCase()
  51. if (releaseTarget == null || releaseTarget == "") {
  52. throw new GradleException("Invalid build type: " + buildType)
  53. }
  54. if (!supportedAbis.contains(defaultAbi)) {
  55. throw new GradleException("Invalid default abi: " + defaultAbi)
  56. }
  57. // Find scons' executable path
  58. File sconsExecutableFile = null
  59. def sconsName = "scons"
  60. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  61. ? [".bat", ".cmd", ".ps1", ".exe"]
  62. : [""])
  63. logger.lifecycle("Looking for $sconsName executable path")
  64. for (ext in sconsExts) {
  65. String sconsNameExt = sconsName + ext
  66. logger.lifecycle("Checking $sconsNameExt")
  67. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  68. if (sconsExecutableFile != null) {
  69. // We're done!
  70. break
  71. }
  72. // Check all the options in path
  73. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  74. if (!allOptions.isEmpty()) {
  75. // Pick the first option and we're done!
  76. sconsExecutableFile = allOptions.get(0)
  77. break
  78. }
  79. }
  80. if (sconsExecutableFile == null) {
  81. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  82. } else {
  83. logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  84. }
  85. // Creating gradle task to generate the native libraries for the default abi.
  86. def taskName = getSconsTaskName(buildType)
  87. tasks.create(name: taskName, type: Exec) {
  88. executable sconsExecutableFile.absolutePath
  89. args "--directory=${pathToRootDir}", "platform=android", "target=${releaseTarget}", "android_arch=${defaultAbi}", "-j" + Runtime.runtime.availableProcessors()
  90. }
  91. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  92. tasks["merge${buildType}JniLibFolders"].dependsOn taskName
  93. }
  94. }