2016-01-20 182 views
1

我在Android Studio中实现了一个名为“proximity”的库项目,并生成了一个“.aar”。这个aar我已经添加到一个新的测试项目作为一个模块,如下所述:https://stackoverflow.com/a/24894387/2791503 此外,我将模块作为与传递标志的依赖关系,因为它已经在这里提出:https://stackoverflow.com/a/25730092/2791503 这可能是gradle File for新TestProject:AAR传递依赖关系Google位置服务

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 
} 

不过,当我启动应用程序,它告诉我,它无法找到一类谷歌的位置API,这是我的库模块的依赖。

java.lang.NoClassDefFoundError: Failed resolution of: 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:[email protected]' 
    //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') 
} 

这是gradle这个build文件的外观导入库作为一个模块引用AAR后:

configurations.create("default") 
artifacts.add("default", file('app-release.aar')) 
+1

本地android库项目通常会自动提供它们的依赖关系。 –

+0

听起来合乎逻辑,但不幸的是,这对我不起作用 –

+0

您是如何定义邻近库的依赖关系的? –

回答

0

所以我找到了一个适合我的解决方案,但这仍然不是我所希望的......所以让我知道是否有人有更好的解决方案。 无论如何,这可能有助于某人: 我有两个库,一个外部库,库项目本身和一个内部libaray这是外部库的依赖。此外,每个库都有自己的依赖关系,例如内部库引用google-location-service。我试过gradlew assemble,它生成外部库的* .aar文件。但是所有这些都是外部库,但没有内部库和所有其他依赖关系。这个讨论说目前还没有办法处理这个问题: How to export AAR including its dependencies?

没有任何意义使用这个aar没有所有的依赖......所以我不得不寻找另一种方式。在包含外部库的Android TestProject中,单击“File->Import Module->"Select the external library"->Finish”,包含内部库在内的所有依赖关系。