简体   繁体   中英

Using protobuf imports (i.e. google/protobuf/timestamp.proto) with wire

I am trying to generate files using the square's Wire . I could run their sample all good, but as soon as I added import "google/protobuf/timestamp.proto"; to their .proto file to check how wire treats timestamps, compiler broke with this exception:

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 ). I expected wire compiler to use protoc from my system and therefore to be able to use it's includes.

Tried running wire with gradle plugin and using precompiled jar to same result.

UPDATE: Also tried using gradle plugin in android studio project to same extent.

* 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)

2) Timestamp is written in proto3 syntax, and so wire just doesn't support it too.

So answer is - you can't import timestamp.proto and use it to generate classes with wire until proto3 support is implemented.

Wire now supports Proto3 and the new types, including Timestamp . You can check the differences in implementation here: https://square.github.io/wire/wire_vs_protoc/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM