我想在Android Studio中发布我的库模块,这是我的gradle
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
...
}
dependencies {
...
}
uploadArchives {
repositories {
mavenDeployer {
repository(url:"http://xxx.git") {
authentication(userName: "xxx", password: "xxx")
}
pom.groupId = 'com.abc.mylib'
pom.artifactId = 'mylib'
pom.version = '1.0.0'
}
}
}
但是,当我运行gradle task uploadArchives 时,控制台会打印这些消息:
Could not find artifact com.abc.mylib:mylib:pom:1.0.0 in remote (http://xxx.git)
Could not find artifact com.abc.mylib:mylib:aar:1.0.0 in remote (http://xxx.git)
:mylib:uploadArchives FAILED
FAILURE: Build failed with an exception.
无法发布配置'档案' 无法部署工件:无法找到工件com.abc.mylib:mylib:aar:1.0.0 in remote(http://xxx.git)
我还将“http://xxx.git”编辑为“http://xxx/raw/master”,但也没有。
请帮忙......
答案 0 :(得分:1)
这就是我解决问题的方式。
像这样编辑您的library_module build.gradle(将身份验证信息存储在local.properties中):
apply plugin: 'com.android.library'
apply plugin: 'maven' // this is a must
android {
...
}
dependencies {
...
}
def artifactGroupId = "com.your.groupid"
def artifactVersion = "0.1.0" // consider add -SNAPSHOT suffix for development branch
def artifactId = "yourmagic"
Properties properties = new Properties()
InputStream inputStream =
project.rootProject.file('local.properties').newDataInputStream();
properties.load(inputStream)
def YOUR_ACCOUNT = properties.getProperty('YOUR_ACCOUNT')
def YOUR_PASSWORD = properties.getProperty('YOUR_PASSWORD')
uploadArchives {
repositories {
mavenDeployer {
repository(url: "your maven url") {
authentication(userName: YOUR_ACCOUNT, password: YOUR_PASSWORD)
}
snapshotRepository(url: "your maven url") {
authentication(userName: YOUR_ACCOUNT, password: YOUR_PASSWORD)
}
pom.groupId = artifactGroupId
pom.artifactId = artifactId
pom.version = artifactVersion
}
}
在那之后,您可以执行任务uploadArchives。
在您的root build.gradle中,添加您的Maven存储库URL,如下所示:
allprojects {
repositories {
...
maven {
url 'your maven url'
}
}
}
在您的app_module build.gradle中,添加您的魔术依赖项
dependencies {
api fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
implementation 'com.your.groupid:yourmagic:0.1.0' // snapshot version 0.1.0-SNAPSHOT
}
希望这会有所帮助。