-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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-lite does not include well-known protos #1889
Comments
Protobuf-lite since beta-4 is now more of a fork than a subset of protobuf-java, which may cause us problems later since lite API is not stable. Also, lite-generated code may now depend on APIs only in protobuf-lite, so our users must depend on the protobuf-lite runtime. Having all our users explicitly override the dependency is bothersome to them and can easily only expose problems only after we do a release. So now we are doing the dependency overriding; most users should "just work" and pick up the correct protobuf artifact. I've confirmed the exclusion is listed in the grpc-protobuf pom and "gradle dependencies" and "mvn dependency:tree" do not include protobuf-lite for the examples. Vanilla protobuf users are most likely to experience any breakage, which should detect problems more quickly since we use protobuf-java more frequently than protobuf-lite during development. protobuf-lite does not include pre-generated code for the well-known protos, so users will need to generate them themselves for the moment (protocolbuffers/protobuf#1889). Note that today changing deps does not noticeably reduce the method code for our users, since ProGuard already is stripping most classes. The difference in output is only a reduction of 3 classes and 6 methods for the android example.
Protobuf-lite since beta-4 is now more of a fork than a subset of protobuf-java, which may cause us problems later since lite API is not stable. Also, lite-generated code may now depend on APIs only in protobuf-lite, so our users must depend on the protobuf-lite runtime. Having all our users explicitly override the dependency is bothersome to them and can easily only expose problems only after we do a release. So now we are doing the dependency overriding; most users should "just work" and pick up the correct protobuf artifact. I've confirmed the exclusion is listed in the grpc-protobuf pom and "gradle dependencies" and "mvn dependency:tree" do not include protobuf-lite for the examples. Vanilla protobuf users are most likely to experience any breakage, which should detect problems more quickly since we use protobuf-java more frequently than protobuf-lite during development. protobuf-lite does not include pre-generated code for the well-known protos, so users will need to generate them themselves for the moment (protocolbuffers/protobuf#1889). Note that today changing deps does not noticeably reduce the method code for our users, since ProGuard already is stripping most classes. The difference in output is only a reduction of 3 classes and 6 methods for the android example.
Protobuf-lite since beta-4 is now more of a fork than a subset of protobuf-java, which may cause us problems later since lite API is not stable. Also, lite-generated code may now depend on APIs only in protobuf-lite, so our users must depend on the protobuf-lite runtime. Having all our users explicitly override the dependency is bothersome to them and can easily only expose problems only after we do a release. So now we are doing the dependency overriding; most users should "just work" and pick up the correct protobuf artifact. I've confirmed the exclusion is listed in the grpc-protobuf pom and "gradle dependencies" and "mvn dependency:tree" do not include protobuf-lite for the examples. Vanilla protobuf users are most likely to experience any breakage, which should detect problems more quickly since we use protobuf-java more frequently than protobuf-lite during development. protobuf-lite does not include pre-generated code for the well-known protos, so users will need to generate them themselves for the moment (protocolbuffers/protobuf#1889). Note that today changing deps does not noticeably reduce the method code for our users, since ProGuard already is stripping most classes. The difference in output is only a reduction of 3 classes and 6 methods for the android example.
This is not only relevant to java but other languages too such as C++. There is also a huge problem when you compile the well-known protos for lite with type compatibility to full runtime (that is same typename in specification, meaning they reside in similar directory structure), that protobuf ships with pre-generated include files for full runtime in system path, and you can't simply workaround this by include path ordering as some compilers such as Xcode don't seem to respect that fully. So basically the runtime specific files provided in system path should be moved to own directory, and tell developers to add that to their include path if they decide to use full runtime (you could also now provide similar directory for lite, if you want to ship pre-generated well-known types). |
The generator also seems to generate PackFrom to UnpackTo methods which depend on symbol only included in full runtime. |
I am still seeing this issue, are other folks experiencing this still? |
Right now well-known types doesn't work with lite runtime. |
For people experiencing this, there is an okay short-term workaround for applications (sorry, no good for libraries) which I alluded to it in my original comment. If using Gradle, you just add a "protobuf" dependency to your build. The normal protobuf jar includes the .protos, so this will extract those to let import work and will generate the code for them.
I think it is harder in Maven, but still possible to some degree. I've not tried it though. The above Gradle snippet appears to work in #2321. |
@xfxyjwf any update ? |
ejona86's workaround doesn't help if you have two Android modules, both of which need the well-known-types, because you then end up with dex failing due to duplicate classes. |
@m-sasha, yes. Android modules like you describe are "libraries". |
Our solution is to shade the well-known protos we use. This is not ideal as it can result in unnecessary duplication, but it beats failing because of conflicts as @m-sasha points out. |
@kamalmarhubi, can you explain what you mean by that? |
I'll make a Java lite release this quarter (Q3), and for well-known types I plan to create a separate Java artifact. |
@kamalmarhubi I'd be interested in hearing more about this as well. @xfxyjwf Is there still a plan for creating a separate well-known types artifact? |
@xfxyjwf Any update on these. For now I am copying the proto files I am using into my src manually. |
Any updates on this? Would prefer not to shade the dependencies unless we absolutely have to. |
@xfxyjwf @BSBandme an update on this? An official javalite artifact would be great, and seems like not too much effort. Fellow googlers over in Firebase land are already doing this. :-) |
Any updates on this? |
I just tested with 3.10.0 and this seems fixed. The |
com.google.protobuf.Any class don't have unpack method. when this problem will be solved? |
I think closing this might have been premature. For example, the inclusion of |
@ericgribkoff, we can discuss some on Wednesday when it can be in-person, but I don't think it should work like that (you can also discuss with @voidzyc). Android users use Gradle and should use the Protobuf Gradle Plugin. The plugin allows you to include a dependency on a .jar file that contains generated code as well as the There are some details where things do break down, like I don't remember if the .proto files are included in the lite jar, you don't actually want the .proto files to be shipped in your app, and a few similar issues. But I do think this is a step in the right direction and there can be some ways to resolve the other issues. |
Here's a great workaround for those who can't wait for an official fix: |
Just tried to use the Android Gradle integration with com.google.protobuf:protobuf-javalite:3.8.0 and com.google.protobuf:protoc:3.8.0. I think the generated code is now missing protobuf.Any.pack() and unpack(). Could not see an issue reported about this yet and this issue in general fits the symptoms. So will pack() and unpack() be added? |
Same issue as @tokohone here. Tried using protobuf-javalite:3.8.0/3.10.0/3.12.2 and same result |
@ejona86 This is still an issue for other well-known protos, such as datetime.proto For those of us shipping libraries in 2023, what's the recommended way forward? I get runtime exceptions when unmarshalling grpc responses that include I can fix that with And, I don't want to ship a library that includes a From my naive perspective, I don't understand the lack of a |
datetime.proto is not a "well-known proto." That is part of the googleapis project, not protobuf. There's no |
Thank you very much for the fast response and clear explanation 🙇🏻 |
It does not include generated code nor .proto files. Users need to compile these themselves, which works okay short-term but also means they can't be used from libraries. We can either include the generated code in the protobuf-lite artifact, or create a new artifact to hold them.
The reasoning behind a new artifact is that, until recently, protobuf-lite was a subset of protobuf, which would no longer be possible if it included lite-generated code for wellknown protos. However, if lite isn't going to be a subset of protobuf again, then putting the generated classes in the same artifact would become easier for everyone.
The text was updated successfully, but these errors were encountered: