我正在使用 android studio。我正在开发一个带有谷歌云应用引擎(端点)和谷歌云存储的应用程序。当我编写 gradle 依赖项时,如下所示:
dependencies {
compile 'com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(path: ':backend', configuration: 'android-endpoints')
compile files('libs/joda-time-2.8.2.jar')
compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4')
compile files('libs/guava-18.0.jar')
}
编译时出现错误:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: com/google/common/reflect/TypeToken$TypeCollector$ForwardingTypeCollector.class
我试过用这种方式排除
compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4'){
exclude group: 'com.google.guava'
}
但没有任何作用。谁能帮帮我?
最佳答案
1) 首先,让我们从您的依赖项中删除这个丑陋的 jar 。我是关于 joda-time 和 Guava
compile 'joda-time:joda-time:2.8.2'
compile 'com.google.guava:guava:18.0'
2) 将 exclude group: 'com.google.guava'
从 appengine
移动到 apis
compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
exclude group: 'com.google.guava'
}
并将其添加到您的:backend
compile (project(path: ':backend', configuration: 'android-endpoints')) {
exclude group: 'com.google.guava'
}
3) 现在你可以得到这个错误 com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '...java'' finished with non-零退出值 1
如果是,我们应该将排除添加到 appengine
compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
exclude group: 'javax.transaction'
}
4) 现在你得到 Duplicate files copied in APK META-INF/NOTICE.txt
我们通过 android {}
部分
packagingOptions
解决了这个问题
packagingOptions {
exclude 'META-INF/NOTICE.txt'
}
所以你的最终结果
android {
...
packagingOptions {
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile (project(path: ':backend', configuration: 'android-endpoints')) {
exclude group: 'com.google.guava'
}
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:multidex:1.0.1'
compile 'joda-time:joda-time:2.8.2'
compile 'com.google.guava:guava:18.0'
compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
exclude group: 'com.google.guava'
}
compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
exclude group: 'javax.transaction'
}
}
关于android - 用 Guava 编译谷歌云服务客户端库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32242229/