我有一个运行grpc
端点的服务器,我想使用 android 客户端连接到该端点。我正在尝试生成所需的..Grpc.java
内容,以便我可以使用这些.newStub()
方法来创建grpc
请求。
我有一个包含以下服务的原始文件:
service StorageNode {
rpc SayHello (StrWrapper) returns (StrWrapper) {}
}
message StrWrapper {
string message = 1;
}
我的 android 应用程序build.gradle
包含protobuf
如下所列的任务和依赖项:
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.9.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
grpc {
option 'lite'
}
}
}
}
}
dependencies {
...
compile 'com.google.protobuf:protobuf-lite:3.0.0'
compile 'io.grpc:grpc-okhttp:1.11.0'
compile 'io.grpc:grpc-protobuf-lite:1.11.0'
compile 'io.grpc:grpc-stub:1.11.0'
}
生成的ProtoFileGrpc.java
文件在构建后包含错误,如下所示:
Error:(51, 64) error: method marshaller in class ProtoUtils cannot be applied to given types;
required: T
found: StrWrapper
reason: inferred type does not conform to upper bound(s)
inferred: StrWrapper
upper bound(s): Message
where T is a type-variable:
T extends Message declared in method <T>marshaller(T)
Error:(927, 40) error: cannot find symbol method getDescriptor()
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.