我在 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'))