适用于kotlin android的gRPC:导入“ google / protobuf / wrappers.proto”无效

时间:2018-10-05 08:29:41

标签: android kotlin protocol-buffers grpc tensorflow-serving

我创建了一个gRPC项目,该项目与用于kotlin android项目的示例gRPC非常相似,位于 https://github.com/grpc/grpc-java/tree/master/examples/example-kotlin/android/helloworld

如果我使用示例原始文件,则构建过程将正常进行。 但是现在,我用不同的原型替换了原型文件,Gradle无法构建我的项目。

这是失败的原始文件:

syntax = "proto3";

package tensorflow.serving;
option cc_enable_arenas = true;

import "google/protobuf/wrappers.proto";

// Metadata for an inference request such as the model name and version.
message ModelSpec {
  // Required servable name.
  string name = 1;

  // Optional version.
  google.protobuf.Int64Value version = 2;

  // A named signature to evaluate. If unspecified, the default signature will
  // be used.
  string signature_name = 3;
}

错误消息是:

  Cause: protoc: stdout: . stderr: app/build/extracted-include-protos/main: warning: directory does not exist.
  app/build/extracted-include-protos/main: warning: directory does not exist.
  app/src/debug/proto: warning: directory does not exist.
  app/src/debug/proto: warning: directory does not exist.
  google/protobuf/wrappers.proto: File not found.
  model.proto: Import "google/protobuf/wrappers.proto" was not found or had errors.
  model.proto:30:3: "google.protobuf.Int64Value" is not defined.

1 个答案:

答案 0 :(得分:0)

普通protobuf jar附带的“知名” protos不包含在kotlin Android示例使用的protobuf-lite jar中。在https://github.com/protocolbuffers/protobuf/issues/1889

中跟踪了此问题

作为解决方法,您可以将普通protobuf jar中的原型添加到您的项目中:

dependencies {
  protobuf 'com.google.protobuf:protobuf-java:3.5.1'
}