-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
RuntimeException in MessageSchema on Android with Proguard #6463
Comments
Any updates on this? Is this a bug? going forward is javalite runtime always going to use reflection and not work with proguard/r8? |
Is there any workaround for this? Edit: adding the following line to your proguard-rules file helps to get rid of the error but keep in mind that your protobuf messages will then not be processed by proguard at all.
|
I've added a proguard config here as a workaround. Please let me know if it doesn't solve the problem. |
Using a proguard exception is a workaround AT MOST, but definitely not a solution! I still think reflection should not be used in lite variant at all. |
I think this was needed to remove unused fields from a message. @donaldchai could you please add more context? |
MessageSchema is used to avoid generating hashCode/equals/(de)serialization methods since a small schema would be more compact. Reflection is used to initialize the internal schema data structures the first time. Removal of unused fields is not directly related. I filed https://issuetracker.google.com/issues/144631039 for R8 to support obfuscation. |
I am not able to get around this when using above proguard rule: Is there any alternative or any other configuration that I should try. |
@jombie I'm running with the same problem, did you find out a solution? |
The following config works for me:
|
AndroidX Security delegates crypto operation to Tink which depends on Protobuf Javalite. Recently Protobuf Javalite introduced a change that relies on reflection, which doesn't work with Proguard. This change adds a rule that keeps the (shaded) Protobuf classes in Tink as-is. See also: - https://buganizer.corp.google.com/issues/154315507 - tink-crypto/tink#361 - protocolbuffers/protobuf#6463 - https://b.corp.google.com/issues/144631039
The proguard rule worked for me but increased my app size by 3 MBs 😞 |
This proguard rule raise a new exception:
downgrade |
Ack. What a lame bug. ProGuard is generally enabled on release builds but not debug builds by default in Android Studio, so the result is APK/App Bundles that use protobuf crash immediately on startup but debug versions are totally fine. Also, why is this issue closed? Seems like a critical bug. |
@tucson-tom it's not a bug, and it's not critical. Proto Messages use reflection in some cases, which Proguard can't know about unless you describe it in its rules. Just add a Proguard rule and that's it, that's basically why those rules exist |
This issue caused lots of problems in my library, I am not a Java developer personally and could not reproduce issue for a long time. Now looking at the reason it seems to me that things are broken in Protobuf Java ecosystem. There should be at least a way for library developers to avoid asking library users to add proguard rules manually into their project. Maybe this way already exists? |
I'm having problems as well, as I'd like to keep the code obfuscated. It is possible to turn of the use of reflection? |
There is a way: Library should include pro guard rules in |
Seems the generator we're using is outputting code which is not designed to be obfuscated, so unless you're up for writing your own generator, disabling obfuscation with proguard rules is the only alternative. |
We are having the same issue. The only solution we currently have is using the following rule in ProGuard which seems to work as expected. I believe this should be handled on the protobuf library. Here is the rules that work:
And here is the rule that generates the problem mentioned here:
Another solution would be to keep the members of the classes but let them obfuscated like so:
and then adding a -dontnote Let us know if there would be a version that we could use. This only happens after we migrated from Lite version to the new javalite versions. I pretty much tested all without the RC versions so far. |
Re: https://crrev.com/c/4063747 and protocolbuffers/protobuf#6463 Bug: 1395764 Change-Id: Id598afb69167d85de27e14281f368649a30564d0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4067023 Commit-Queue: Stefano Duo <[email protected]> Reviewed-by: Tommy Nyquist <[email protected]> Auto-Submit: Stefano Duo <[email protected]> Cr-Commit-Position: refs/heads/main@{#1079833}
Version: v3.9.0
Language: Java/Android
Protoc gradle plugin 0.8.10 for java with option "lite"
When running an proguard obfuscated android app a Runtime Exception is thrown when trying to build a Proto with it's Builder.
It seems than since 3.8.0 the new Javalite runtime uses reflection for the Schemas. I thought the lite should NOT be using any reflection at all.
The text was updated successfully, but these errors were encountered: