java - 程序类型已存在 : com. google.common.annotations.GwtCompatible

标签 java android android-studio

我在构建 Android 项目时遇到以下错误:

Program type already present: com.google.common.annotations.GwtCompatible Message{kind=ERROR, text=Program type already present: com.google.common.annotations.GwtCompatible, sources=[Unknown source file], tool name=Optional.of(D8)}

gradle文件:

 apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId "com.example.www.www"
            minSdkVersion 15
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

            // multi-dex support (When your app and the libraries it references exceed 65,536 methods)
            multiDexEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/ASL2.0'
            exclude 'META-INF/INDEX.LIST'
        }
    }

    dependencies {
        // multi-dex support (When your app and the libraries it references exceed 65,536 methods)
        implementation 'com.android.support:multidex:1.0.3'


        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.0'
        implementation 'com.android.support:design:27.1.1'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


        //this is for the google "text recognizer"
        implementation 'com.google.android.gms:play-services-vision:15.0.2'
        implementation 'com.google.apis:google-api-services-customsearch:v1-rev63-1.23.0'


        //for firebase database connection
        implementation 'com.google.firebase:firebase-database:16.0.1'
        //implementation 'com.google.firebase:firebase-core:16.0.0'
        // for firebase authentication
        implementation 'com.google.firebase:firebase-auth:16.0.1'
        implementation 'com.google.android.gms:play-services-auth:15.0.1'


        // for Google Natural Language Processing (part of google cloud services)
        implementation ('com.google.cloud:google-cloud-language:1.31.0')
              //  {
              //      exclude group: 'com.google.guava'
              //  }

    }


    apply plugin: 'com.google.gms.google-services'

以下解决了该问题:

implementation ('com.google.cloud:google-cloud-language:1.31.0') { 
    exclude group: 'com.google.guava'
}

但是我缺少 guava 函数,因为在运行时会抛出以下错误:

Didn't find class "com.google.common.base.MoreObjects"

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/MoreObjects;

当我运行以下代码时: 公共(public)无效testSomething(查看 View ){

    // Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
        try {
            InputStream inputStream = getAssets().open("www.json");

            GoogleCredentials googleCredential = GoogleCredentials.fromStream(inputStream);
    }
    catch (Exception e){
        Log.e(TAG,e.getMessage());
        e.printStackTrace();
    }

我在这里兜圈子。我迫切地想找到答案。 我检查了其他问题/主题,没有找到对我有帮助的答案。

最佳答案

我通过进行以下更改解决了同样的问题:

implementation ('com.google.apis:google-api-services-drive:v2-rev105-1.17.0-rc'){
    exclude module: 'guava-jdk5'
}
implementation ('com.google.api-client:google-api-client-android:1.20.0'){
    exclude module: 'guava-jdk5'
}

关于java - 程序类型已存在 : com. google.common.annotations.GwtCompatible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50653030/

相关文章:

java - 进度条 setVisibility VISIBLE

java - JLabel 或 JButton 如何告诉 JScrollPane View 大小已更改?

Java 文件等于

android - 如何为矢量绘图添加阴影?

android - 如何从 Android 应用程序中删除 firebase 身份验证用户?

android - 如何在主机上部署 XMPP 服务器以与 Android 客户端一起使用?

java - 何时为 Tiles 使用 View Preparer

android - 在 Android MediaStore.EXTRA_DURATION_LIMIT 中无法在 6.0 及更高版本的设备中工作

android-studio - Flutter : What are the differences between Flutter Plugin, Flutter 包和 Flutter 模块?

android - org.gradle.api.ProjectConfigurationException : A problem occurred configuring project ':app'