Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use google/api/annotations.proto with Android

I have a problem with proto file in my project I had import in my proto file:

import "google/api/annotations.proto";

I am getting following error when building the project.

Import "google/api/annotations.proto" was not found or had errors.

How can I use this import in my project? Should I add something to my build.gradle?

like image 616
Stanislav Mukhametshin Avatar asked Oct 27 '25 23:10

Stanislav Mukhametshin


1 Answers

On non-Android, you could add this dependency to your build.gradle:

compile 'com.google.api.grpc:proto-google-common-protos:1.12.0'

However, Android uses Protobuf "Lite" instead of full Protobuf and there's not a pre-generated library with Lite for this proto. There is an open issue about this.

However, a workaround discussed for the well-known protos can be used here as well. Namely, use a protobuf dependency instead of a compile dependency. This will generate the code as part of your build.

protobuf 'com.google.api.grpc:proto-google-common-protos:1.12.0'

Unfortunately, this solution only really works for applications. If two libraries use this "solution" they must never be included into the same application as they will have duplicated (and potentially have different versions of) the generated classes.

like image 183
Eric Anderson Avatar answered Oct 30 '25 14:10

Eric Anderson