Grpc是一种在移动端使用很方便、快捷的数据传递方式:
以下是Grpc在Android中的一些只要的配置方式
首先是需要导入以下的依赖:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':v2_library')
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.google.guava:guava:18.0'
compile 'javax.annotation:javax.annotation-api:1.2'
// You need to build the https://github.com/grpc/grpc-java
// to obtain these libraries below.
compile 'io.grpc:grpc-protobuf-nano:0.13.2'
compile 'io.grpc:grpc-okhttp:0.13.2'
compile 'io.grpc:grpc-stub:0.13.2'
compile 'com.google.protobuf:protobuf-java:3.0.0-beta-2'
}
在build.gradle中添加如下节点:
apply plugin: 'com.google.protobuf'
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0-beta-2'
// artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:0.13.2'
}
}
// generateProtoTasks {
// all()*.plugins {
// grpc {}
// }
// }
generateProtoTasks {
all().each { task ->
task.builtins {
javanano {
// Options added to --javanano_out
option 'ignore_services=true'
}
}
task.plugins {
grpc {
// Options added to --grpc_out
option 'nano=true'
}
}
}
}
}
在外层build.gradle中添加:
buildscript { dependencies { classpath "com.google.protobuf:protobuf-gradle-plugin:0.7.0" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
如此便可以了,, 导入.proto文件使用Grpc方式飞吧。