我在我的gitlab存储库中托管了一个依赖项,我试图在另一个项目中访问它。我在另一个项目的根build.gradle中提供了我的存储库的路径,但由于某种原因,gradle生成的用于获取依赖关系的URL无效。我一直试图弄清楚我可能做错了什么,但到目前为止我无法确定问题所在。
我发布了用于生成aar文件的gradle代码以及尝试在另一个Android应用中获取此依赖项的代码。
库build.gradle文件:
publishing {
publications {
maven(MavenPublication) {
groupId 'com.umer' //You can either define these here or get them from project conf elsewhere
artifactId 'myLibrary'
version project.version
artifact "$buildDir/outputs/aar/myLibrary-release.aar" //aar artifact you want to publish
//generate pom nodes for dependencies
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dependency ->
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
}
}
}
}
//publish to filesystem repo
repositories{
maven {
url "C:\\Users\\Umer\\AndroidStudioProjects\\android\\myLibrary\\artifacts"
}
}
}
Android应用的App Level build.gradle:
dependencies {
provided ('com.umer.myLibrary:myLibrary-1.1')
}
Android应用root root.gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
maven {
url 'http:/GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/BRANCH_NAME/artifacts'
credentials {
username = "myUserName"
password = "myPassword"
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android应用的gradle.properties:
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=12345
org.gradle.jvmargs=-Xmx1536m
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=12345
Android App Project中的Gradle Sync错误:
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.umer.myLibrary:myLibrary-1.1:.
Could not resolve com.umer.myLibrary:myLibrary-1.1:.
Required by:
project :app
> Could not resolve com.umer.myLibrary:myLibrary-1.1:.
> Could not get resource 'http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom'.
> Could not HEAD 'http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom'.
> Connect to 127.0.0.1:12345 [/127.0.0.1] failed: Connection refused: connect
> Connection refused: connect
我该如何解决?
PS:
这是Gradle在Android应用中生成的格式错误的网址。
http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom
答案 0 :(得分:-1)
通过查看格式错误的网址: ' http://GIT_LAB_IP_ADDRESS/dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom'
看起来你有2个问题: 1.您需要使用真实主机名/ ip替换GIT_LAB_IP_ADDRESS。为此你可以使用双引号& $ sign作为占位符:
" HTTP:// $ {GIT_LAB_IP_ADDRESS} /dev/myLibrary/tree/remoteRepoPublication/artifacts/com/umer/myLibrary/myLibrary-1.1//myLibrary-1.1-.pom"
其中GIT_LAB_IP_ADDRESS从local.properties加载或在build.gradle文件中定义。
希望这有帮助。