retrofit配合使用protobuf3

  之前项目中使用了retrofit网络请求框架和protobuf2的数据结构。因为protobuf3出来也有一段时间了,所以准备在新项目中换成protobuf3,但是在如果还是使用以前的那些库会导致编译出来的proto文件全部报错以及retrofit的converter-protobuf无法解析服务端返回的数据,下面给出proto2时候的需要的包,以及proto3时候需要的包。


protobuf2:

compile 'com.squareup.retrofit2:converter-protobuf:2.1.0'
compile 'com.google.protobuf:protobuf-java:2.6.1'


protobuf3:

compile 'com.squareup.retrofit2:converter-protobuf:2.2.0'
compile 'com.google.protobuf:protobuf-java:3.2.0'

要注意,'com.squareup.retrofit2:converter-protobuf'这个库的版本如果是2.1.0或者一下的话是解析不出来protobuf3的数据结构的,converter中用了反射的方法去获取字段的,proto2和proto3是不一样的,所以需要升级到最新的'com.squareup.retrofit2:converter-protobuf:2.2.0'

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值