简体   繁体   English

使用带有线的 protobuf 导入(即 google/protobuf/timestamp.proto)

[英]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/binprotoc位于那里。 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.

相关问题 Protobuf Android 在生成的文件夹中包含构建类型 - Protobuf Android includes build type in generated folders 在 Android 上使用最新的 gRPC 插件时出现组装错误 -> Input 在 --proto_path (Gradle 7.0.1) 中有阴影 - Assemble error while using latest gRPC plugin on Android -> Input is shadowed in the --proto_path (Gradle 7.0.1) 从Jar导入无法解析 - Imports from Jar not resolving 如何找到Google Play版本? - How do I find Google Play version? 删除不必要的gradle导入 - Remove unecessary gradle imports 找不到aapt2-proto.jar(com.android.tools.build:aapt2-proto:0.3.1) - Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1) 用于junit导入的testCompile和androidTestCompile之间的区别 - Differences between testCompile and androidTestCompile for junit imports 无法使用转换 AarTransform 转换文件“45907c80e09917e1b776adf038505958”以匹配属性 {artifactType=jar} - Failed to transform file '45907c80e09917e1b776adf038505958' to match attributes {artifactType=jar} using transform AarTransform 我没有找到正确的解决方案google-service-plugin版本冲突 - I didn't find proper solution google-service-plugin version conflict 在Android Studio / IntelliJ13中无法正常导入,gradle命令行运行正常 - Imports in Android Studio/IntelliJ13 not working, gradle command line running just fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM