【发布时间】:2016-04-26 11:30:28
【问题描述】:
我在 Android Studio 中实现了一个名为“proximity”的库项目并生成了一个“.aar”。这个 aar 我已经作为一个模块添加到一个新的测试项目中,如下所述:https://stackoverflow.com/a/24894387/2791503 此外,我将模块作为具有传递标志的依赖项包含在内,正如这里提出的那样:https://stackoverflow.com/a/25730092/2791503 这可能是新 TestProject 的 gradle 文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile(project(':proximity')) {
transitive=true
}
当我启动应用程序时,它仍然告诉我它找不到 Google Location API 的类,这是我的库模块的依赖项。
java.lang.NoClassDefFoundError:解析失败:Lcom/google/android/gms/common/api/GoogleApiClient$Builder;
如何强制 gradle 包含我的库模块的那些传递依赖项?
编辑: 下面是原库项目的gradle构建文件:
dependencies {
//integration tests
androidTestCompile 'com.android.support.test:runner:0.4.1'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4.1'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator- v18:2.1.2'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
//local unit testing
testCompile 'junit:junit:4.1'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1'
//estimote sdk
compile 'com.estimote:sdk:0.9.4@aar'
//google location api(GPS)
compile 'com.google.android.gms:play-services-location:8.4.0'
//Google Guave Java Util
compile 'com.google.guava:guava:18.0'
//custom BeSpoon library for android
compile project(':bespoonlibrary')
}
这是将库作为引用 aar 的模块导入后 gradle 构建文件的外观:
configurations.create("default")
artifacts.add("default", file('app-release.aar'))
【问题讨论】:
-
本地android库项目通常会自动提供依赖。
-
听起来合乎逻辑,但不幸的是这对我不起作用
-
你是如何定义邻近库的依赖关系的?
-
我已经编辑了原始问题,因此可以看到所有依赖项
-
您使用的是哪个 gradle 版本和 Android 插件?
标签: java android android-studio gradle transitive-dependency