android studio 加载.proto不能生成xxxDrpc的问题

第一步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文件夹的建立。


成功效果图


你可能感兴趣的:(android,android,studio)