具有 gRPC 构建错误的 Cloud Firestore

Cloud Firestore with gRPC build error

我正在开发一个 android 应用程序,它必须使用 gRPC 和 Firestore。但是,当我添加来自“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;

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

implementation ('com.google.firebase:firebase-firestore:11.4.2') {
    exclude group: 'io.grpc'
}

但是出现了同样的错误。然后我想如果我从 grpc 模块依赖项中排除所有'io.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'

当它成功编译时我很惊讶,但在启动应用程序后,它崩溃了 java.lang.RuntimeException: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)

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

由于多种因素限制了我们在 Google 上构建 Android SDK 的方式,Firestore 在其内部保护了 gRPC 的副本。不幸的是,这是有漏洞的,你 运行 正在陷入后果:11.4.2 Firestore SDK 与任何外部 gRPC 不兼容:-(。

这基本上是我们针对 Firestore Android SDK 的首要问题,很抱歉您 运行 参与其中。