build_library.gradle 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 28
  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 false
  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 "com.tencent.luggage"
  41. groupId GROUP_ID
  42. artifactId POM_ARTIFACT_ID
  43. version rootProject.ext.versionName
  44. packaging "aar"
  45. }
  46. withXml {
  47. Node root = asNode()
  48. def depsNode = root["dependencies"][0] ?: root.appendNode("dependencies")
  49. depsNode.children().removeAll { true }
  50. if (project.ext.has('pomDeps')) {
  51. project.ext.pomDeps.each { String path, String version ->
  52. def paths = path.split(':')
  53. def group = paths[0]
  54. def artifactId = paths[1]
  55. def node = depsNode.appendNode('dependency')
  56. node.appendNode('groupId', group)
  57. node.appendNode('artifactId', artifactId)
  58. node.appendNode('version', version)
  59. node.appendNode('scope', "compile")
  60. }
  61. }
  62. }
  63. }.writeTo("${dir}/${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.pom")
  64. }
  65. }
  66. def localAar = 'localAar'
  67. def localAarGroupPath = GROUP_ID.replace(".", "/")
  68. def aarDir = rootProject.file("${localAar}/${localAarGroupPath}/${POM_ARTIFACT_ID}/${rootProject.ext.versionName}")
  69. .with {
  70. it.mkdirs()
  71. return it
  72. }
  73. task copy {
  74. doLast {
  75. println("copy file ${POM_ARTIFACT_ID}")
  76. copy {
  77. from("${buildDir}/outputs/pom/") {
  78. include "*.pom"
  79. }
  80. into aarDir
  81. }
  82. copy {
  83. from("${buildDir}/outputs/aar/") {
  84. include "*-release.aar"
  85. }
  86. rename {
  87. return "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.aar"
  88. }
  89. into aarDir
  90. }
  91. }
  92. }
  93. task zip(type: Zip) {
  94. archiveName "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}.zip"
  95. destinationDir aarDir
  96. from(aarDir) {
  97. include '*.aar'
  98. include '*.pom'
  99. }
  100. }
  101. task zipmapping(type: Zip) {
  102. archiveName "${POM_ARTIFACT_ID}-${rootProject.ext.versionName}-mapping.zip"
  103. destinationDir rootProject.file("${buildDir}/outputs/mapping/")
  104. from(rootProject.file("${buildDir}/outputs/mapping/release/")) {
  105. include '*.txt'
  106. }
  107. }
  108. afterEvaluate {
  109. // build.finalizedBy(zip, zipmapping)
  110. // 只需要zip mapping,模块的zip在流水线里处理
  111. build.finalizedBy(zipmapping)
  112. zipmapping.dependsOn(copy)
  113. copy.dependsOn(generatePom)
  114. }
  115. ext.clearDuplicatedJniLibs = { files ->
  116. afterEvaluate {
  117. task clearTask {
  118. doFirst {
  119. def buildDir = buildDir
  120. files = files.collect {
  121. "/intermediates/exploded-aar/$it"
  122. }
  123. delete(fileTree(dir: buildDir, includes: files))
  124. }
  125. }
  126. project.tasks.all { task ->
  127. def name = task.name
  128. if (name.contains('merge') && name.contains('JniLibFolders')) {
  129. task.dependsOn(clearTask)
  130. }
  131. }
  132. clearTask.mustRunAfter(project.tasks.matching { task -> task.name.contains('explode') })
  133. }
  134. }