第一步protobuff插件的下载,
第二步 gradle的配置两个 app gradle的配置
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'com.google.protobuf'




android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "cn.efarm360.com.animalhusbandry"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
    }
}
protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.2'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.0.2' // CURRENT_GRPC_VERSION
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}




dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.google.code.findbugs:jsr305:3.0.0'
    compile 'com.google.guava:guava:18.0'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.android.support:appcompat-v7:25.0.0'
    testCompile 'junit:junit:4.12'
 
   
    // You need to build grpc-java to obtain these libraries below.
    compile 'io.grpc:grpc-okhttp:1.0.2'
    // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-protobuf-lite:1.0.2'
    // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-stub:1.0.2'
    // CURRENT_GRPC_VERSION
    compile 'javax.annotation:javax.annotation-api:1.2'
   
}
tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

外部gradle的配置 buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'https://code.lds.org/nexus/content/groups/main-repo/' }
        maven{ url 'http://maven.ibiblio.org/maven2/' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
       //注解的使用
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
           //grpc的使用
        classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
       
    }
}


allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'https://code.lds.org/nexus/content/groups/main-repo/' }
        maven{ url 'http://maven.ibiblio.org/maven2/' }
        jcenter()
        mavenLocal()
    }
}


task clean(type: Delete) {
    delete rootProject.buildDir
}
第三步proto文件夹的建立。

成功效果图

更多相关文章

  1. android中使用wakelock
  2. android中使用wakelock
  3. 解决android TextView多行文本(超过3行)使用ellipsize属性无效问题
  4. 使用Android系统自带的icon图标
  5. Android中ProgressDialog的简单示例
  6. Android剪切图片
  7. android:shape的使用
  8. 使用air进行移动app开发常见功能和问题(二)
  9. 提供一些Android免费课程分享给大家

随机推荐

  1. Android(安卓)Handler机制详解:在线程中新
  2. 英特尔® Android* USB 驱动程序安装指南
  3. android中刷新Invalidate和postInvalidat
  4. 解析Android中的XML
  5. Android(安卓)学习笔记——利用JNI技术在
  6. Android(安卓)XML解析学习——Dom方式
  7. Android中各种JAVA包的功能描述
  8. 安卓中一些常用的属性小结
  9. Android消息机制
  10. Android(安卓)内存泄露分析