【问题标题】:Updated firebase dependency and got duplicated protobuf classes error更新了 firebase 依赖并得到重复的 protobuf 类错误
【发布时间】:2020-10-27 01:58:13
【问题描述】:

更新我的一个 Firebase SDK 后出现此错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractParser found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractProtobufList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.BooleanArrayList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.ByteBufferWriter found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
...

我的应用现在依赖于protobuf-liteprotobuf-javalite,这会触发重复类错误。

【问题讨论】:

    标签: android firebase protocol-buffers


    【解决方案1】:

    此错误表示您正在为您的项目导入两个使用 Protobuf 的包,其中一个的发行版与另一个冲突。
    如果您在 Flutter 上遇到此问题,您可以重新考虑 pubspec.yaml 中依赖项的版本号,并将“any”替换为确切的版本号。
    例如,在“依赖项:”下更改:

    barcode_scan: any
    

    收件人:

    barcode_scan: ^2.0.0
    

    希望我能帮上忙。

    【讨论】:

      【解决方案2】:

      我通过在 Gradle 依赖树中手动搜索并随后更新有问题的 SDK 解决了这个问题。

      对于 Android,请使用此行

      gradle app:dependencies > dependency_tree.txt
      

      或者如果你有一个 gradle 包装器:

      ./gradlew app:dependencies > dependency_tree.txt
      

      app 是您的项目模块。

      然后在dependency_tree.txt 文件中手动搜索proto 以查找有问题的SDK。

      【讨论】:

        【解决方案3】:
        【解决方案4】:

        对我来说,我只是降级了我的com.google.firebase:firebase-firestore:21.5.0 -> com.google.firebase:firebase-firestore:21.4.3

        【讨论】:

          【解决方案5】:

          在我的情况下,问题是依赖于 protobuf-liteandroidx.security:security-crypto:1.0.0-alpha02 库,它与 Firebase 使用的 protobuf-java-lite 冲突。更新这个库有帮助。

          您可以通过在终端中调用./gradlew app:dependencies 来检查其他库是否依赖于冲突的protobuf-lite。然后 cmd+f 搜索proto

          【讨论】:

          【解决方案6】:

          尝试降级

          implementation 'com.google.firebase:firebase-firestore:21.4.3'
          implementation 'com.google.firebase:firebase-config:19.1.4'
          

          它适用于

          implementation 'androidx.mediarouter:mediarouter:1.1.0'
          implementation 'com.google.android.gms:play-services-cast-framework:18.1.0'
          

          【讨论】:

            【解决方案7】:

            最近,Firebase Android 已从依赖旧的 protobuf-lite 迁移到依赖于 protobuf-javalite (github issue | PR implementing the change)。

            您需要同时更新所有受此更改影响的 Firebase SDK,否则旧的 SDK 会将错误的依赖项拉入您的应用。

            以下是受影响的 SDK 列表及其支持 protobuf-javalite 的版本

            - com.google.firebase:firebase-firestore:21.5.0
            - com.google.firebase:firebase-inappmessaging:19.1.0
            - com.google.firebase:firebase-inappmessaging-display:19.1.0
            - com.google.firebase:firebase-config:19.2.0
            - com.google.firebase:firebase-abt:19.1.0
            - com.google.firebase:firebase-perf:19.0.8
            

            编辑:将firebase-perf 添加到列表中,因为它传递地依赖于配置并且也需要更新。

            【讨论】:

            • 我目前正在使用com.google.firebase:firebase-firestore:21.5.0。据我所知,这是最新版本,但我仍然收到错误。
            • 您是否还依赖于列表中的任何其他 SDK?您需要更新所有这些。
            • 没有。只有com.google.firebase:firebase-firestore:21.5.0。我最终降级到以前的版本。
            • 您的应用程序中的其他非 Firebase 依赖项很可能正在拉取 protobuf-lite 依赖项。在此处查看如何获取您的应用程序的依赖关系树stackoverflow.com/questions/21645071/…
            猜你喜欢
            • 1970-01-01
            • 2019-01-05
            • 2021-10-16
            • 2016-05-30
            • 2019-12-17
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多