打包aar并进行远程依赖,解决引用aar时找不到aar的远程依赖库问题
一、找到需要打包的Module,在build.gradle中添加如下信息
plugins {
id 'maven'
}
ext {
GITHUB_REPO_PATH = "D://JNChatSdk/AAR"
PUBLISH_GROUP_ID = 'wgd.jnchat.lib'
PUBLISH_ARTIFACT_ID = 'JNChatSdk'
PUBLISH_VERSION = '1.0.2'
}
uploadArchives {
repositories {
mavenDeployer {
//本地maven仓库地址,也可以使用远程maven仓库
def deployPath = file(project.GITHUB_REPO_PATH)
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId project.PUBLISH_GROUP_ID
artifactId project.PUBLISH_ARTIFACT_ID
version project.PUBLISH_VERSION
}
}
}
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
artifacts {
archives androidSourcesJar
}
二、运行以下命令生成aar文件
gradlew uploadArchives
三、上传aar文件至GitHub仓库中
四、引用远程aar
1.在项目的gradle中添加:
allprojects {
repositories {
maven { url "https://raw.githubusercontent.com/WGDrzjz/JNChatSDK/master" }
}
}
2.在Module的gradle中添加:
implementation 'wgd.jnchat.lib:JNChatSdk:1.0.2'
至此你可以依赖使用你的库了。