Search code examples
javaandroidgradleprotocol-buffers

Gradle protoc plugin doesn't find default google proto file


My proto files use default google protocolbuffers types such as struct and timestamp.

Using the default gradle protoc integration, gradle outputs errors because it can not resolve imports:

google/protobuf/struct.proto: File not found.

google/protobuf/timestamp.proto: File not found.

Replacing the default gradle protoc block

protoc {
    artifact = 'com.google.protobuf:protoc:3.3.0'
}

with one specifying where protoc is

protoc {
    path = '/usr/local/bin/protoc'
}

fixes the issue but it is not portable.

Is there any jar dependency or other portable solution that could make the default gradle protoc definition working?


Solution

  • Adding the following dependencies fixes the error:

    compile 'com.google.protobuf:protobuf-java:3.4.0'

    The dependency provides default google protofiles along the compiled protobuf library.

    From Gradle 6+, use implementation:

    dependencies {
      // https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java
      implementation 'com.google.protobuf:protobuf-java:3.21.10'
    }