build.gradle 3.7 KB

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