方法中的Marshaller错误在Android上生成Grpc服务

时间:2018-04-22 09:18:57

标签: java android protocol-buffers grpc-java protobuf-java

我有一台运行..Grpc.java端点的服务器,我想使用Android客户端连接到该端点。我正在尝试生成所需的.newStub(),以便我可以使用grpc方法创建service StorageNode { rpc SayHello (StrWrapper) returns (StrWrapper) {} } message StrWrapper { string message = 1; } 请求。

我有一个proto文件,其中包含以下服务:

build.gradle

我的Android应用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. 文件在构建后会包含错误,如下所示:

{{1}}

1 个答案:

答案 0 :(得分:0)

问题似乎是因为javax.annotation-api未包含在依赖项中。对于生成的@javax.annotation.Generated似乎正在使用的...Grpc.java,这是必需的。

包括以下似乎已经解决了这个问题。

dependencies {
    ...
    compile "javax.annotation:javax.annotation-api:1.2"
}