【问题标题】:Method Marshaller errors in protoc generated Grpc Services on Androidprotoc 中的方法 Marshaller 错误在 Android 上生成 Grpc 服务
【发布时间】:2018-04-22 09:18:57
【问题描述】:

我有一个运行 grpc 端点的服务器,我想使用 android 客户端连接到该端点。我正在尝试生成所需的..Grpc.java,以便我可以使用.newStub() 方法来创建grpc 请求。

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

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.

【问题讨论】:

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


    【解决方案1】:

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

    包括以下内容似乎已经解决了问题。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2015-09-10
      • 1970-01-01
      • 2017-01-08
      • 2016-09-19
      • 1970-01-01
      相关资源
      最近更新 更多