protobuf序列化
使用参考:README.md
https://github.com/google/protobuf-gradle-plugin
https://jingyan.baidu.com/article/925f8cb8a6c21ac0dce0566e.html
https://www.jianshu.com/p/0f047e1b7e16
开发环境
Android studio 3.6.1
jdk 1.8
gradle 5.6.4
gradle 插件 3.6.1
1.引入插件
在工程目录下的build.gradle中添加如下:
classpath ‘com.google.protobuf:protobuf-gradle-plugin:0.8.13’
buildscript {
repositories {
google()
jcenter()
//第一步
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
//第三步
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
}
}
allprojects {
repositories {
google()
jcenter()
//第二步
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在module下的build.gradle
apply plugin: 'com.android.application'
//第四步
apply plugin: 'com.google.protobuf'
android {
///第五步
sourceSets {
main {
java {
srcDir 'src/main/java'
}
proto {
srcDir 'src/main/protobuf' //指定.proto文件路径
include '**/*.proto'
}
}
}
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "io.gitbub.protobuf"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}