build_library.gradle 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. apply plugin: 'com.android.library'
  2. apply plugin: 'org.jetbrains.kotlin.android'
  3. apply plugin: 'maven'
  4. android {
  5. compileSdk rootProject.ext.compileSdkVersion
  6. defaultConfig {
  7. minSdk rootProject.ext.minSdkVersion
  8. targetSdk rootProject.ext.targetSdkVersion
  9. versionName rootProject.ext.versionName
  10. consumerProguardFiles "consumer-rules.pro"
  11. setProperty("archivesBaseName", "${archivesBaseName}-$versionName")
  12. }
  13. lintOptions {
  14. abortOnError false
  15. }
  16. buildTypes {
  17. release {
  18. minifyEnabled true
  19. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  20. }
  21. }
  22. compileOptions {
  23. sourceCompatibility JavaVersion.VERSION_1_8
  24. targetCompatibility JavaVersion.VERSION_1_8
  25. }
  26. kotlinOptions {
  27. jvmTarget = '1.8'
  28. }
  29. }
  30. def GROUP_ID = "com.donut.plugin"
  31. task generatePom {
  32. doLast {
  33. println "generate pom ${POM_ARTIFACT_ID}"
  34. def dir = project.file("${project.buildDir}/outputs/pom/")
  35. if (!dir.exists()) {
  36. dir.mkdirs()
  37. }
  38. pom {
  39. project {
  40. groupId GROUP_ID
  41. artifactId POM_ARTIFACT_ID
  42. version rootProject.ext.versionName
  43. packaging "aar"
  44. }
  45. withXml {
  46. Node root = asNode()
  47. def depsNode = root["dependencies"][0] ?: root.appendNode("dependencies")
  48. depsNode.children().removeAll { true }
  49. if (project.ext.has('pomDeps')) {
  50. project.ext.pomDeps.each { String path, String version ->
  51. def paths = path.split(':')
  52. def group = paths[0]
  53. def artifactId = paths[1]
  54. def node = depsNode.appendNode('dependency')
  55. node.appendNode('groupId', group)
  56. node.appendNode('artifactId', artifactId)
  57. node.appendNode('version', version)
  58. node.appendNode('scope', "compile")
  59. }
  60. }
  61. }
  62. }.writeTo("${dir}/${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.pom")
  63. }
  64. }
  65. def localAar = 'localAar'
  66. def localAarGroupPath = GROUP_ID.replace(".", "/")
  67. def aarDir = rootProject.file("${localAar}/${localAarGroupPath}/${POM_ARTIFACT_ID}/${rootProject.ext.versionName}")
  68. .with {
  69. it.mkdirs()
  70. return it
  71. }
  72. task copy {
  73. doLast {
  74. println("copy file ${POM_ARTIFACT_ID}")
  75. copy {
  76. from("${buildDir}/outputs/pom/") {
  77. include "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.pom"
  78. }
  79. into aarDir
  80. }
  81. copy {
  82. from("${buildDir}/outputs/aar/") {
  83. include "*-release.aar"
  84. }
  85. rename {
  86. return "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.aar"
  87. }
  88. into aarDir
  89. }
  90. }
  91. }
  92. task zip(type: Zip) {
  93. archiveName "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.zip"
  94. destinationDir aarDir
  95. from(aarDir) {
  96. include '*.aar'
  97. include '*.pom'
  98. }
  99. }
  100. task zipmapping(type: Zip) {
  101. archiveName "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}-mapping.zip"
  102. destinationDir rootProject.file("${buildDir}/outputs/mapping/")
  103. from(rootProject.file("${buildDir}/outputs/mapping/release/")) {
  104. include '*.txt'
  105. }
  106. }
  107. afterEvaluate {
  108. build.finalizedBy(zipmapping)
  109. zipmapping.dependsOn(copy)
  110. copy.dependsOn(generatePom)
  111. }
  112. ext.clearDuplicatedJniLibs = { files ->
  113. afterEvaluate {
  114. task clearTask {
  115. doFirst {
  116. def buildDir = buildDir
  117. files = files.collect {
  118. "/intermediates/exploded-aar/$it"
  119. }
  120. delete(fileTree(dir: buildDir, includes: files))
  121. }
  122. }
  123. project.tasks.all { task ->
  124. def name = task.name
  125. if (name.contains('merge') && name.contains('JniLibFolders')) {
  126. task.dependsOn(clearTask)
  127. }
  128. }
  129. clearTask.mustRunAfter(project.tasks.matching { task -> task.name.contains('explode') })
  130. }
  131. }