【发布时间】:2015-12-24 19:57:59
【问题描述】:
设置
我有一个 android 项目设置方式如下:Main 取决于 Module A 和 Module A 取决于 模块 B。
A 和 B 都编译成 aar 文件并上传到本地 maven 存储库。在主项目中,模块 A 的导入是显式的。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(group: 'com.test', name: 'ModuleA', version: '0.0.1', changing: true)
}
错误
在运行 Main 项目时,在 Module A 使用 Module B 的地方失败并出现 NoClassDefFoundError。
一旦我将模块 B 显式导入到主项目中,此错误就消失了。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(group: 'com.test', name: 'ModuleA', version: '0.0.1', changing: true)
compile(group: 'com.test', name: 'ModuleB', version: '0.0.1', changing: true)
}
问题
gradle 不能自动解决依赖关系?还是我必须在 Main 项目的 build.gradle 中包含所有 Module A 的依赖项?
我认为它与 pom 文件的生成有关,在 pom 文件中你可以定义依赖部分。我们如何让 gradle 知道在生成 pom 文件时包含依赖项?
编辑#1
ModuleA 的 build.gradle 如下所示:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(group: 'com.test', name: 'ModuleB', version:'0.0.1', ext: 'aar', changing: true)
}
publishing {
publications {
aar(MavenPublication) {
groupId packageId
version = versionId
artifactId libraryId
artifact("$buildDir/outputs/aar/${project.getName()}-debug.aar")
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
maven = true
username = "admin"
password = "password"
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
resolve {
repository {
repoKey = 'libs-release'
maven = true
}
}
}
【问题讨论】:
-
您在模块 A 中是否“提供”了模块 B 的依赖项?
-
@AlbertoAnderickJr 嗯...我有一个“编译”依赖项。
-
尝试放置提供的依赖项,然后您可以在主项目中使用 ModuleA 和 ModuleB 依赖项进行编译
-
@AlbertoAnderickJr,你的意思是在 ModuleA 的 build.gradle 中有一个 ModuleB 的“提供”范围导入吗?我认为“编译”范围既是“提供”又是“包”
-
将 ModuleB 打包成 ModuleA 可能是您的问题的原因
标签: android android-studio gradle