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

991 views Asked by At

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:
2

There are 2 answers

1
aleien On BEST ANSWER

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.

0
oldergod On

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/