[英]Using protobuf imports (i.e. google/protobuf/timestamp.proto) with wire
I am trying to generate files using the square's Wire .我正在尝试使用 square 的Wire生成文件。 I could run their sample all good, but as soon as I added
import "google/protobuf/timestamp.proto";
我可以很好地运行他们的示例,但是一旦我添加了
import "google/protobuf/timestamp.proto";
to their .proto file to check how wire treats timestamps, compiler broke with this exception:到他们的 .proto 文件以检查 wire 如何处理时间戳,编译器因此异常而中断:
Exception in thread "main" java.io.FileNotFoundException: Failed to locate google/protobuf/timestamp.proto in [src/main/proto]
I have protoc in my path ( $PATH=...usr/local/bin
, protoc
is located in there. timestamp.proto
is located under /usr/local/include/google/protobuf
).我有protoc在我的路径(
$PATH=...usr/local/bin
, protoc
位于那里。 timestamp.proto
位于下/usr/local/include/google/protobuf
)。 I expected wire compiler to use protoc from my system and therefore to be able to use it's includes.我希望有线编译器使用我系统中的 protoc,因此能够使用它的包含。
Tried running wire with gradle plugin and using precompiled jar to same result.尝试使用 gradle 插件运行 wire 并使用预编译的 jar 来获得相同的结果。
UPDATE: Also tried using gradle plugin in android studio project to same extent.更新:还尝试在 android studio 项目中以相同的程度使用 gradle 插件。
* What went wrong:
Execution failed for task ':app:generateProtos'.
> unable to resolve 1 imports:
google/protobuf/timestamp.proto
searching 0 proto paths:
Ok, after some searching and experimenting, turns out that:好的,经过一些搜索和实验,结果是:
1) Wire doesn't support proto3 syntax (yet) 1) Wire不支持 proto3 语法(尚)
2) Timestamp is written in proto3 syntax, and so wire just doesn't support it too. 2)时间戳是用proto3语法编写的,所以wire也不支持它。
So answer is - you can't import timestamp.proto and use it to generate classes with wire until proto3 support is implemented.所以答案是 - 在实现 proto3 支持之前,您不能导入 timestamp.proto 并使用它来生成带有线的类。
Wire now supports Proto3 and the new types, including Timestamp
. Wire 现在支持 Proto3 和新类型,包括
Timestamp
。 You can check the differences in implementation here: https://square.github.io/wire/wire_vs_protoc/您可以在此处检查实现的差异: https : //square.github.io/wire/wire_vs_protoc/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.