-
Notifications
You must be signed in to change notification settings - Fork 41
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
Android Gradle conflict with Google firebase-firestore: protobuf-lite nested dependency #11
Comments
It seems Capillary should be using protobuf-lite for the generated code in If you run into trouble using lite, I may be able to help. |
I simply added the line:
to the capillary_internal.proto, and both modules now build without error! I guess now I will try to build the jar and use it in my test projects. |
|
I lack the knowledge and documentation to apply the plugin: com.google.protobuf:protoc-gen-javalite to the Gradle files myself in any meaningful way. Its always a little unnerving when trying to add things to a project that haven't been maintained in almost 3 years and are not mentioned in any documentation that I can find. Though, according to the official Protobuf documentation:
|
I'd file a bug, but protocolbuffers/protobuf#5110 already exists. Basically, LITE is being rewritten internally and when ready will reemerge as a beautiful butterfly that will dazzle all. But as part of that, LITE is now a completely separate runtime from full proto (they share APIs, but not implementations). In any case, the optimize_for option has been found to be "the wrong thing," because it's really the consumer of the .proto that should determine what it is optimized for, not the producer (proto author). For example, in Android you want LITE and for server you want full :-D Using com.google.protobuf:protoc-gen-javalite should be basically the same as using the grpc-java plugin (and replacing "grpc" with "javalite" in the various references). You might find https://github.com/grpc/grpc-java#generated-code useful. |
ok, I see now that it is a plugin for protoc itself, therefore I should remove the gradle protobuf plugins that automatically generate code, and instead generate the code manually using protoc and then put it in the into the appropriate source directories... protoc-gen-javalite |
You'll want a |
Inside the gradle.build for the 'lib' module (this is the only module generating protobuf code) the protobuf{} definition now looks like this:
I am no longer using |
also the sourceDirs inside the idea{} block needs to be changed to .../javalite instead of .../java. Ideally, the lib-android module of this library should be independent of the server-side 'lib' module. This way the lib can use the full :protobuf-java dependency, and the 'lib-android' can use :protobuf-lite, with both modules generating the protobuf code independently. |
Also: In order to run the Capillary Server (lib) alongside the 'com.google.firebase:firebase-admin:6.8.0' dependency required for Firestore, you must also include dependency: |
With this library, please use "com.google.firebase:firebase-firestore:15.0.0" If you want to use firestore with higher version, you can use command: "gradlew app: androidDependencies" to identify child components in firestore, and only implement necessary components. |
@jakett I tried your method and it didn't work, since the incompatibility is far beyond include missing classes (or remove duplicates). AFAIK it is not possible to use protobuf-java and firestore newer than 15. I tried 15 and my first Firestore code line throw an exception (the one I use for token auth). Use version 15 is not an option. Google should provide a compatibility version of Firestore 21.4.3 with protobuf-java 3.11.4. Unfortunately I am not able to use protobuf-javalite since I need Any message and reflection. Is there another way to accomplish that? I have to decide to move away from Firestore or to implement the same functionality of the Any message myself. Regards, |
@jakett oh man, thank you so much. I love you bro ❤️ |
Describe the bug
I am attempting to test Capillary in a simple Android app (on device), but during the gradle build process I am getting "Error: Program type already present: com.google.protobuf.AnyProto" (or other classes).
I am using Google Firebase-Firestore DB, which implements grpc and uses nested dependency: com.google.protobuf:protobuf-lite:3.0.1.
Also, the google/Capillary library uses nested dependency: com.google.protobuf:protobuf-java:3.4.0.
If I exclude com.google.protobuf from the Capillary lib dependency only, the app will run, then crash when RSAKeyManager is instantiated, with error: "java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3;" (I will not be implementing any direct client -> capillary service grpc, as both will have access to Firestore DB, and the capillary service will not be exposed to ingress)
To Reproduce
I assume that adding google/Firestore dependencies to the demo/Android app will also cause this build error. It will sync/build in Android Studio, but build error occurs only when the app is run.
Expected behavior
Through some form of gradle dependency exclusions, will I be able to get these packages to run in the same Android app?
Screenshots
I have tried using several combinations of package exclusions, including fully excluding com.google.protobuf from both Firestore and Capillary and implementing either separately:
The text was updated successfully, but these errors were encountered: