Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuf-java and protobuf-javalite conflict #8104

Closed
danwaters-stripe opened this issue Nov 30, 2020 · 4 comments
Closed

protobuf-java and protobuf-javalite conflict #8104

danwaters-stripe opened this issue Nov 30, 2020 · 4 comments

Comments

@danwaters-stripe
Copy link

What version of protobuf and what language are you using?
Version: v3.11.4
Language: Java

What operating system (Linux, Windows, ...) and version?
Mac OS 10.15.7

What did you do?
Including both protobuf-java and protobuf-javalite causes duplicate class errors on build. The simplest reproduction is to just include both as dependencies:

implementation "com.google.protobuf:protobuf-javalite:3.11.0"
implementation "com.google.protobuf:protobuf-java:3.11.4"

This will generate these errors on build:

Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-java-3.11.4 (com.google.protobuf:protobuf-java:3.11.4) and jetified-protobuf-javalite-3.11.0 (com.google.protobuf:protobuf-javalite:3.11.0)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-java-3.11.4 (com.google.protobuf:protobuf-java:3.11.4) and jetified-protobuf-javalite-3.11.0 (com.google.protobuf:protobuf-javalite:3.11.0)
...

Even more concerning to me is that you get the same errors even when you just include dependencies on libraries that use these two different libraries. Like firebase:

implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation "com.google.firebase:firebase-firestore"
implementation "com.google.protobuf:protobuf-java:3.11.4"

Since we publish a library that has a dependency on protobuf-java, this means that our library will always conflict with any library that uses protobuf-javalite.

@vikasrairajput
Copy link

@danwaters-stripe , any luck to resolve this issue?

@perezd
Copy link
Contributor

perezd commented Jul 26, 2021

Sorry for late response, protobuf-java and protobuf-javalite should never be included in the same project, and here's why:

protobuf-java contains both the lite and non-lite runtime inside itself and is primarily targeted for use in JVM server binaries where reflection capabilities are not seriously problematic for performance if the end user choses to use them.

protobuf-javalite contains only the essential lite runtime and no support for reflection-based APIs, which is often preferred for size and speed constraints on mobile JVM platforms like Android.

Currently we do not make protobuf-javalite a dependency of protobuf-java and at the moment do not have plans to separate them out this way. The fact is, the end user should never include both, this is an error (accidental or otherwise).

Now you might ask yourself, OK, but what if I do end up doing that (or a transitive dependency does)? Well, if you're using Gradle, we recommend an approach like this: https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html#sec:excluding-transitive-deps

Telling the system to exclude protobuf-javalite because you explicitly depend on protobuf-java is technically OK, but this might have negative side effects to performance or code size on mobile platforms, it also might be totally fine for you, your mileage may vary.

As a good rule of thumb, if you're publishing an Android-targeted library, its recommended you depend on protobuf-javalite and the larger ecosystem should be compatible with you. If you run into an unexpected condition, exclusion is probably the best bet.

@bitsydarel
Copy link

In this case, @perezd, would it make sense to provide a kotlin-lite version as well?

Unfortunately, protobuf-kotlin has a dependency on protobuf-java, which causes this duplicate issue.

#14830

@bitsydarel
Copy link

hoo found it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants