更新时间:2022-06-12 22:52:27
好的,这是一个常见问题。在其他项目中使用Android库(AAR)有多种方式。例如:
implementation project(':mylibrary')
。注意:
我推荐什么?
我建议开发人员使用MavenLocal()
,它在将您的AAR发布到Jitpack之类的公共存储库或您想要的任何位置之前复制真实的场景。
我该如何做?
apply plugin: 'maven-publish'
project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
setGroupId 'YOUR_GROUP_ID'
//You can either define these here or get them from project conf elsewhere
setArtifactId 'YOUR_ARTIFACT_ID'
version android.defaultConfig.versionName
artifact bundleReleaseAar //aar artifact you want to publish
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
运行assemble
和publishToMavenLocal
分级任务。你会看到类似这样的东西:
allprojects {
repositories {
mavenLocal()
...
}
}
implementation '${YOUR_GROUP_ID}:${YOUR_ARTIFACT_ID}:${YOUR_VERSION}'