protobuf是google开源的序列化解决方案,本文只做记录配置,具体自行百度
protobuf的AS插件地址
https://github.com/google/protobuf-gradle-plugin
1 在AS项目根目录下的 build.gradle
dependencies下 增加classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
2在app目录下的build.gradle配置
apply plugin: 'com.google.protobuf'
protobuf {//和android同级
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
3 最后dependencies下加入implementation 'com.google.protobuf:protobuf-lite:3.0.0'
最后编写 .protobuf文件 buidl项目 将会在app\build\generated\source\proto\debug\javalite 下生成相应的class文件