Andorid Studio 集成 Google Protocol Buffer(简称protobuf)

Andorid Studio 集成 Google Protocol Buffer(简称protobuf)
一、配置gradle导如protobuf
1、项目的build.gradle文件中加入
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'

2、模块的build.gradle文件
顶部添加protobuf插件
apply plugin: 'com.google.protobuf'
android结点增加proto文件位置配置
sourceSets {
    main {
        proto {
            srcDir 'src/main/proto'
            include '**/*.proto'
        }
        java {
            srcDir 'src/main/java'
        }
    }
}
添加依赖
compile 'com.google.protobuf:protobuf-java:3.1.0'
compile 'com.google.protobuf:protoc:3.1.0'
增加protobuf结点
protobuf {
protoc {
    artifact = 'com.google.protobuf:protoc:3.1.0'
}
generateProtoTasks {
    all().each { task ->
        task.builtins {
            remove java
        }
        task.builtins {
            java {}
            // Add cpp output without any option.
            // DO NOT omit the braces if you want this builtin to be added.
            cpp {}
        }
    }
}
generatedFilesBaseDir = "$projectDir/src/generated"
}
到此为止我们的protobuf就加入成功了下面附上完整的代码
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion 23
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.protobuf.vargo.protobuf"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            proto {
                srcDir 'src/main/proto'
                include '**/*.proto'
            }
            java {
                srcDir 'src/main/java'
            }
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'suppor
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值