美文网首页
protobuf 在android中的使用

protobuf 在android中的使用

作者: 一方乌鸦 | 来源:发表于2020-06-08 23:01 被阅读0次

首先加入插件

    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.12'
    }

然后在 build.gradle 中做配置

apply plugin: 'com.google.protobuf'

android {
    // .proto 文件地址
    sourceSets {
        main {
            proto {
                srcDir 'src/main/proto'
            }
        }
    }

    protobuf {
        protoc {
            artifact = 'com.google.protobuf:protoc:3.8.0'
        }
        generateProtoTasks {
            all().each { task ->
                task.builtins {
                    java {}
                }
            }
        }
        generatedFilesBaseDir = "$buildDir/proto"
    }
}

dependencies {
    implementation 'com.google.protobuf:protobuf-java:3.8.0'
    implementation 'com.google.protobuf:protoc:3.8.0'
    // json 与 proto 互转的库
    implementation 'com.googlecode.protobuf-java-format:protobuf-java-format:1.4'
}

最后 make project 即可生成对应类

相关文章

网友评论

      本文标题:protobuf 在android中的使用

      本文链接:https://www.haomeiwen.com/subject/hoxjtktx.html