Protocol Buffers ,你了解吗?

44 篇文章 0 订阅

已识乾坤大,犹怜草木青

由于公司业务发展,需要开发海外版项目,深入了解 Firebase 在此不得不羡慕国外开发者的幸福啊。在国内,我们可能需要集成多家的SDK,而Firebase算是集大成者。

Firebase 基于Google基础架构而构建,其提供了登录授权,用户数据分析,数据库,消息推送及性能监测与崩溃报告等功能,详细内容,请移步:Firebase官网

今天,在集成 Firebase Crashlytics 崩溃分析报告Firebase Performance Monitoring 性能监测时,在app/build.gradle中添加以下两句话:

 	// Add the Firebase Crashlytics SDK.
    implementation 'com.google.firebase:firebase-crashlytics:17.1.1'

    // Add the dependency for the Performance Monitoring library
    implementation 'com.google.firebase:firebase-perf:19.0.7'

重新编译时遇到了以下错误:

 java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
 
 Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and 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 protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)

大概意思是:protobuf-javalite 和 protobuf-lite包含了相同的类。

很显然,看到Duplicate 就知道是重复问题。最简单的办法就是在其中采用exclude 即可。即:

 // Add the Firebase Crashlytics SDK.
    implementation 'com.google.firebase:firebase-crashlytics:17.1.1'

    // Add the dependency for the Performance Monitoring library
    implementation 'com.google.firebase:firebase-perf:19.0.7', {
        exclude group: 'com.google.protobuf'
    }

这里有几个相关内容的议题:
1. java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite when adding firebase remote config

2. Migrate Firebase SDKs from protobuf-lite to protobuf-javalite

3. Duplicate class exception


WTF protobuf ?

今日的主角—— Google Protocol Buffers

Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler.
Protocol buffers 是Google的语言无关、平台无关、可扩展的序列化结构数据格式,相较于XML,更小,更快,更简单。

推荐一篇文章:Google Protocol Buffer 的使用和原理

读完这篇文章,我们不难猜测出,为什么只有在Firebase特定的几个功能(Firebase RemoteConfig,Firebase Crashlytics 崩溃分析报告,Firebase Performance Monitoring 性能监测 and so on…)会看到protobuf()的身影。


想要更多了解Protocol buffers 的详细内容,请参看:Protobuf的Github地址

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值