首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Google语言库添加到Android应用程序时会出现重复的类

将Google语言库添加到Android应用程序时会出现重复的类
EN

Stack Overflow用户
提问于 2021-09-29 16:03:29
回答 1查看 291关注 0票数 0

当我试图构建Android应用程序时,我遇到了一个问题,它出现了错误。在我在Gradle构建文件(自然语言库)中添加最后一行后,会出现错误。下面是我的gradle构建文件代码

代码语言:javascript
复制
plugins {
    id 'com.android.application'
    id 'com.google.secrets_gradle_plugin' version '0.5'
    id 'com.google.gms.google-services'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.myvolunteer"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-firestore:23.0.3'
    implementation 'com.firebaseui:firebase-ui-firestore:8.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.google.firebase:firebase-database:20.0.2'
    implementation 'com.google.firebase:firebase-storage:20.0.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // Import the BoM for the Firebase platform

    // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation 'com.google.firebase:firebase-analytics:19.0.1'

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

    //Circle Image View
    implementation 'de.hdodenhof:circleimageview:3.1.0'

    //Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'

    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    implementation 'com.karumi:dexter:6.2.3'
    implementation 'com.google.android.gms:play-services-location:18.0.0'


    //Cloud-lang,but it causes duplicate classes occur.
    implementation 'com.google.cloud:google-cloud-language:2.1.2'


}

当我尝试在Android中构建这个项目时,我会遇到一些错误(这太多了,我不能把它们都放在这里)

代码语言:javascript
复制
Duplicate class com.google.api.Advice found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.api.AuthProvider$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.cloud.audit.AuthenticationInfo$Builder found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)
Duplicate class com.google.longrunning.Operation$1 found in modules proto-google-common-protos-2.5.0 (com.google.api.grpc:proto-google-common-protos:2.5.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)

我如何解决这个问题?我真的需要添加谷歌自然语言库到我的应用程序。

更新:我尝试过但失败的尝试:

Firebase Android: Duplicate Protobuf classes found in modules

Duplicate Class while using firebase and google-cloud-texttospeech

EN

回答 1

Stack Overflow用户

发布于 2021-09-30 07:47:53

重复类异常意味着您的依赖项之一隐式地使用您也在项目中使用的某个库的旧版本或更新版本(with +),

为了解决这个问题,您可以将这样的代码块(将库版本放在‘force’之后)添加到您的build.gradle文件中(Module:app):

代码语言:javascript
复制
configurations {
   all {
      resolutionStrategy {
          // do not upgrade above 3.12.0 to support API < 21 while server uses
          // COMPATIBLE_TLS, or okhttp3 is used in project
          force 'com.squareup.okhttp3:okhttp:3.12.0'
          force 'com.squareup.okhttp3:logging-interceptor:3.12.0'
      }
   }
}

您还可以从依赖项中排除某些组。对于一个依赖项,您可以这样写:

代码语言:javascript
复制
dependencies {

    // example
    implementation('log4j:log4j:1.2.15') {
        exclude group: 'javax.jms', module: 'jms'
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69379857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档