Moxy icon indicating copy to clipboard operation
Moxy copied to clipboard

Add proguard rules to support R8 full mode

Open dzmpr opened this issue 1 year ago • 1 comments

Resolves #141

dzmpr avatar Apr 12 '24 14:04 dzmpr

Thanks for the PR!

The problem from the linked issue is caused by R8 performing class merging optimization (similar to what is described in this article). However, AddToEndSingleStrategy relies on commands to have different Classes. Therefore, we need to disable the optimization of classes that extend ViewCommand. This can achieved by using the following proguard rule:

-keep,allowobfuscation,allowshrinking class * extends moxy.viewstate.ViewCommand { *; }

I believe this rule is enough to fix the issue.


Regarding the issue, where R8 removes custom strategies. Moxy uses Class.newInstance() to reflectively create an instance of custom strategy given a strategy Class. However, in full mode, R8 removes the constructor, as stated in R8 FAQ:

The default constructor (<init>()) is not implicitly kept when a class is kept.

So we need to write a rule to keeps this constructor:

-keepclassmembers class * extends moxy.viewstate.strategy.StateStrategy {
    <init>();
}

aasitnikov avatar May 07 '24 19:05 aasitnikov

@aasitnikov Can confirm that suggested rules are enough to fix problem. I updated PR.

dzmpr avatar May 16 '24 13:05 dzmpr