build.gradle 3.7 KB

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