【问题标题】:compiling google cloud service client library with guava使用 guava 编译谷歌云服务客户端库
【发布时间】:2015-08-27 06:32:49
【问题描述】:

我正在使用安卓工作室。我正在使用谷歌云应用引擎(端点)和谷歌云存储开发一个应用程序。当我编写 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'
}

但是没有任何效果。有人可以帮帮我吗?

【问题讨论】:

    标签: android google-app-engine gradle guava


    【解决方案1】:

    1) 首先,让我们从依赖项中删除这个丑陋的 jar。我是约 joda-time 和番石榴

    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-zero exit value 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'
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2018-03-26
    • 2017-11-11
    • 2016-03-21
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 2017-03-14
    • 1970-01-01
    相关资源
    最近更新 更多