ViewBinding and proguard rules for obfuscation
See original GitHub issueIf you are using the abstract class ViewBindingEpoxyModelWtihHolder and you have obfuscation with R8 enabled, then the code does not work because it is trying to get the reflected bind
method from the ViewBinding class. Since bind
is not part of the ViewBinding interface and gets added only in implementations the reflection is the only way to go.
To solve this the following rule should be added to proguard:
-keepclassmembers class <package name of your app>.databinding.** {
public <methods>;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5
Top Results From Across the Web
ProGuard Manual: Examples - Guardsquare
Useful configurations and examples for ProGuard. ... These options shrink, optimize, and obfuscate the single Android activity com.example.MyActivity :
Read more >Troubleshooting ProGuard issues on Android - Medium
There are also versions of the three keep rules that only prevent obfuscation (renaming), but don't prevent shrinking. You can take look at...
Read more >ProGuard with AppBundle and data-binding - android
I have a multi-module project (I use Android App Bundles) with data-binding, ViewModel. But ...
Read more >Shrink, obfuscate, and optimize your app - Android Developers
In fact, R8 works with all of your existing ProGuard rules files, so updating the Android ... Enables code shrinking, obfuscation, and optimization...
Read more >Data Binding class missing during runtime with Proguard on in ...
Proguard set on for library module. ... -dontwarn android.databinding. ... are providing library output as SDK for partners so code obfuscation is needed....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Both problems can be solved with this proguard rules
and don’t forget to change the class paths to point to your package for the
ViewBinding
classes and toViewBindingEpoxyModelWithHolder
class. Apparently R8 somehow messes up the classes and when thebind
method of theViewBinding
class is trying to be resolved, this linewill incorrectly resolve the superclass. I’ve created a vanilla project and tried it with only my classes and the problem is there as well so it has nothing to do with Epoxy per se.
So the solution, even though I don’t know the original cause, is to keep those EpoxyModels extending from
ViewBindingEpoxyModelWithHolder
and don’t allow R8 to mess with themThe controller where it crashed, wasn’t even inflating this model. I have a build running in production with the same code.
It’s only after I upgraded to:
JDK: 11 Gradle: 7.0.4 Arctic Fox
that all my problems started. Worst part is, it’s working fine in debug. Obviously it has something to do with
proguard
. These are my proguard rules if that helps:This is the model class: