build.gradle 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. apply plugin: 'com.android.library'
  2. apply plugin: 'kotlin-android'
  3. ext {
  4. PUBLISH_VERSION = getGodotPublishVersion()
  5. PUBLISH_ARTIFACT_ID = 'godot'
  6. }
  7. apply from: "../scripts/publish-module.gradle"
  8. dependencies {
  9. implementation libraries.kotlinStdLib
  10. implementation libraries.androidxFragment
  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: getGodotLibraryVersion()]
  21. }
  22. namespace = "org.godotengine.godot"
  23. compileOptions {
  24. sourceCompatibility versions.javaVersion
  25. targetCompatibility versions.javaVersion
  26. }
  27. lintOptions {
  28. abortOnError false
  29. disable 'MissingTranslation', 'UnusedResources'
  30. }
  31. packagingOptions {
  32. exclude 'META-INF/LICENSE'
  33. exclude 'META-INF/NOTICE'
  34. // 'doNotStrip' is enabled for development within Android Studio
  35. if (shouldNotStrip()) {
  36. doNotStrip '**/*.so'
  37. }
  38. }
  39. sourceSets {
  40. main {
  41. manifest.srcFile 'AndroidManifest.xml'
  42. java.srcDirs = ['src']
  43. res.srcDirs = ['res']
  44. aidl.srcDirs = ['aidl']
  45. assets.srcDirs = ['assets']
  46. }
  47. debug.jniLibs.srcDirs = ['libs/debug']
  48. release.jniLibs.srcDirs = ['libs/release']
  49. }
  50. libraryVariants.all { variant ->
  51. variant.outputs.all { output ->
  52. output.outputFileName = "godot-lib.${variant.name}.aar"
  53. }
  54. def buildType = variant.buildType.name.capitalize()
  55. def releaseTarget = buildType.toLowerCase()
  56. if (releaseTarget == null || releaseTarget == "") {
  57. throw new GradleException("Invalid build type: " + buildType)
  58. }
  59. if (!supportedAbis.contains(defaultAbi)) {
  60. throw new GradleException("Invalid default abi: " + defaultAbi)
  61. }
  62. // Find scons' executable path
  63. File sconsExecutableFile = null
  64. def sconsName = "scons"
  65. def sconsExts = (org.gradle.internal.os.OperatingSystem.current().isWindows()
  66. ? [".bat", ".cmd", ".ps1", ".exe"]
  67. : [""])
  68. logger.lifecycle("Looking for $sconsName executable path")
  69. for (ext in sconsExts) {
  70. String sconsNameExt = sconsName + ext
  71. logger.lifecycle("Checking $sconsNameExt")
  72. sconsExecutableFile = org.gradle.internal.os.OperatingSystem.current().findInPath(sconsNameExt)
  73. if (sconsExecutableFile != null) {
  74. // We're done!
  75. break
  76. }
  77. // Check all the options in path
  78. List<File> allOptions = org.gradle.internal.os.OperatingSystem.current().findAllInPath(sconsNameExt)
  79. if (!allOptions.isEmpty()) {
  80. // Pick the first option and we're done!
  81. sconsExecutableFile = allOptions.get(0)
  82. break
  83. }
  84. }
  85. if (sconsExecutableFile == null) {
  86. throw new GradleException("Unable to find executable path for the '$sconsName' command.")
  87. } else {
  88. logger.lifecycle("Found executable path for $sconsName: ${sconsExecutableFile.absolutePath}")
  89. }
  90. // Creating gradle task to generate the native libraries for the default abi.
  91. def taskName = getSconsTaskName(buildType)
  92. tasks.create(name: taskName, type: Exec) {
  93. executable sconsExecutableFile.absolutePath
  94. args "--directory=${pathToRootDir}", "platform=android", "target=${releaseTarget}", "android_arch=${defaultAbi}", "-j" + Runtime.runtime.availableProcessors()
  95. }
  96. // Schedule the tasks so the generated libs are present before the aar file is packaged.
  97. tasks["merge${buildType}JniLibFolders"].dependsOn taskName
  98. }
  99. // TODO: Enable when issues with AGP 7.1+ are resolved (https://github.com/GodotVR/godot_openxr/issues/187).
  100. // publishing {
  101. // singleVariant("release") {
  102. // withSourcesJar()
  103. // withJavadocJar()
  104. // }
  105. // }
  106. }