-
Notifications
You must be signed in to change notification settings - Fork 34
Description
I’m experiencing a ClassCastException when starting my GlobalActivity. The error occurs during Presenter injection in the MoxyKtxDelegate (specifically in the providePresenter method). When using R8 full mode, the crash happens consistently. However, switching to R8 compatibility mode (by setting android.enableR8.fullMode=false) allows the app to run without crashing.
What I’ve Tried:
• Added the following ProGuard/R8 rules to preserve necessary classes and attributes:
-keepattributes Signature,RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations,EnclosingMethod,InnerClasses
-keep class moxy.** { *; }
-keep class moxy.ktx.** { *; }
-keepclasseswithmembers class * {
@moxy.InjectPresenter <fields>;
}
-keep,allowobfuscation class * extends moxy.MvpPresenter { *; }
-keep class *$$Lambda$* { *; }
# Do not obfuscate meta-information with annotations
-keepattributes *Annotation*
# Do not obfuscate classes with Injected Presenters
-keepclasseswithmembernames class * { @moxy.presenter.InjectPresenter <fields>; }
# Do not obfuscate names of classes with Injected View States
-keepnames @moxy.InjectViewState class *
# Do not obfuscate presenters names
-keepnames class * extends moxy.MvpPresenter
# Do not obfuscate PresentersBinder autogenerated classes
-keep class **$$PresentersBinder { *; }
# Do not obfuscate ViewStateProvider autogenerated classes
-keep class **$$ViewStateProvider { *; }
# Keep Moxy classes
-keep class moxy.** { *; }
# Don't warn about unresolved references of coroutines, androidx classes etc
-dontwarn moxy.**
# R8 with full mode can remove *Command classes with same signature which breaks command queue
# More info: https://github.com/moxy-community/Moxy/issues/141
-keep,allowobfuscation,allowshrinking class * extends moxy.viewstate.ViewCommand { *; }
# R8 with full mode removes custom strategy default constructor
-keepclassmembers class * extends moxy.viewstate.strategy.StateStrategy {
<init>();
}
Despite these rules, the ClassCastException still occurs in full mode.
I suspect that R8 full mode might be aggressively optimizing or merging classes that are critical for Presenter injection, causing issues during type casting.
Any guidance on additional rules or adjustments needed to safely run in R8 full mode would be greatly appreciated.
Thanks for your help!