Cloud Firestore 出现 gRPC 构建错误

1 android gradle firebase grpc google-cloud-firestore

我正在开发一个必须使用 gRPC 和 Firestore 的 android 应用程序。但是,当我从 'io.grpc' 组依赖项(例如 io.grpc:grpc-okhttp:1.7.0)和 firestore 依赖项(com.google.firebase:firebase-firestore:11.4.2)中添加模块之一时在构建 gradle 配置中,我收到构建错误“无法合并 dex”。使用 'stacktrace' 构建选项后,我看到问题是

Multiple dex files define Lio/grpc/internal/OobChannel$5;
Run Code Online (Sandbox Code Playgroud)

如果 firestore 使用 grpc-core 模块,则可能会发生这种情况,但树依赖项中没有类似的模块,这是我使用 [androidDependencies] gradle 任务获得的。我试图像这样排除 io.grpc:

implementation ('com.google.firebase:firebase-firestore:11.4.2') {
    exclude group: 'io.grpc'
}
Run Code Online (Sandbox Code Playgroud)

但有同样的错误。然后我想如果我排除所有'io.grpc'会怎样。来自 grpc 模块依赖项的传递依赖项,为内部类添加 grpc-core。就这样,我写了丑陋的依赖只是为了测试

implementation 'com.google.firebase:firebase-firestore:11.4.2'
implementation('io.grpc:grpc-okhttp:1.7.0') {
    exclude group: 'io.grpc'
}
implementation('io.grpc:grpc-protobuf-lite:1.7.0') {
    exclude group: 'io.grpc'
}
implementation('io.grpc:grpc-stub:1.7.0') {
    exclude group: 'io.grpc'
}
implementation 'io.grpc:grpc-core:1.7.0'
Run Code Online (Sandbox Code Playgroud)

当它成功编译时我很惊讶,但在启动应用程序后,它崩溃了 java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev)

Caused by: java.lang.NoSuchMethodError: No static method zzcyc()Lio/grpc/ManagedChannelProvider; in class Lio/grpc/ManagedChannelProvider; or its super classes (declaration of 'io.grpc.ManagedChannelProvider' appears in /data/app/com.zipr.test-2/split_lib_dependencies_apk.apk)
Run Code Online (Sandbox Code Playgroud)

我使用 gradle 3.0.0-rc1 并启用 multidex 支持。我删除了 .gradle,构建目录,清理重建的项目,但我仍然有构建错误。我能做些什么来解决这个问题?

Gil*_*ert 5

由于各种因素限制了我们在 Google 构建 Android SDK 的方式,Firestore 会在自身内部保护 gRPC 的副本。不幸的是,这是有漏洞的,您会遇到后果:11.4.2 Firestore SDK 与任何外部 gRPC 都不兼容 :-(。

这基本上是 Firestore Android SDK 的首要问题,很抱歉您遇到了它。