使用 firebase 和 dialog-flow 解决重复 类

Resolve duplicate classes with firebase and dialog-flow

我正在开发一个移动应用程序,我需要对话流才能从用户消息中获取一些信息。问题是,当我在应用 gradle 中实现对话流时,我在构建时遇到错误,说我有多个重复的 classes(与 firebase classes 冲突)。

我试过这里建议的方法:

甚至在对话流的 github 存储库中进行了搜索: https://github.com/googleapis/google-cloud-java/issues/5608#issue-462434090

我试图排除 'google-protobuf',但这没有帮助(我在对话流组件上遇到编译错误)。

我在下面附上了我的依赖项。

dependencies {
    implementation 'com.hbb20:ccp:2.2.4'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.firebase:firebase-database:17.0.0'
    implementation 'com.google.firebase:firebase-firestore:19.0.2'
    implementation 'com.google.cloud:google-cloud-dialogflow:0.99.0-alpha'
}

编辑 这些是 gradle 指定的一些重复项: 在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-google-common-protos 中发现重复 class com.google.api.Advice -1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-[=78 中发现重复 class com.google.api.Advice$1 =]-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

重复 class com.google.api.Advice$Builder 在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

重复 class com.google.api.AdviceOrBuilder 在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-[=78= 中发现重复 class com.google.api.AnnotationsProto ]-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

在模块 classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) 和 proto-[=78= 中发现重复 class com.google.api.AuthProto ]-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)

将以下代码段添加到您的 build.gradle,然后 运行 gradle findDuplicates。这将列出任何重复的 类 以及它们所在的罐子。之后您可以看到要排除的罐子。

task findDuplicates {
   doLast {
      Map<String, List<File>> pathMap = [:] 
      configurations.runtime.each { file ->
         FileTree tree = file.directory ? fileTree(file) : zipTree(file) 
         tree.visit { FileVisitDetails fvd ->
            if (!fvd.directory) {
               String path = fvd.path
               List<File> fileList = pathMap[path]?:[] 
               fileList << fvd.file
               pathMap[path] = fileList
            } 
         } 
      } 
      pathMap.each { path, fileList ->
         if (fileList.size() > 1) {
            println "Found duplicate $path in $fileList" 
         } 
      } 
   } 
} 

I have the duplicate classes and it's jars, but I never excluded something from gradle. Could you please help me out? For example, I have this: "Duplicate class com.google.api.Advice found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and proto-google-common-protos-1.16.0.jar (com.google.api.grpc:proto-google-common-protos:1.16.0)"

我不确定为什么这些 jar 会复制相同的 类 或者你想保留哪一个。但是你可以做类似

的事情
dependencies {
    implementation 'com.hbb20:ccp:2.2.4'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    ... 

} 
configurations.implementation.exclude(group: 'com.google.firebase', module: 'protolite-well-known-types') 

我遇到了同样的问题,经过几个月的调试和从 google 和 firebase 更新后,我找到了一个有效的解决方案。 需要更改 firebase 和对话流程的库版本。 如果您的项目中的最小 SDK 版本小于 19,请将其更改为 19。

Firebase implementation

Dialog flow implementation