我已经在Android Studio中实现了一个名为“邻近”的图书馆项目,并生成了一个“.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的类,这是我的库模块的依赖项。



如何强制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'))

最佳答案

因此,我找到了一个适合我的解决方案,但仍然不是我想要的...所以请让我知道是否有人有更好的解决方案。
无论如何,这可能会帮助某人:
我有两个库,一个是外部库,一个是库项目本身,另一个是内部libaray,它是对外部库的依赖。此外,每个库都有其自己的依赖性,例如内部库引用google-location-service。

我尝试使用gradlew assemble生成外部库的* .aar文件。但是aar中只有外部库,而没有内部库和所有其他依赖项。讨论表明,到目前为止,尚无办法解决此问题:
How to export AAR including its dependencies?

没有所有依赖关系就没有使用这个aar的感觉...所以我不得不寻找另一种方法。在应包含外部库的Android TestProject中,单击File->Import Module->"Select the external library"->Finish,所有依赖项都在其中,包括内部库。

07-25 22:24
查看更多