After update to AGP 8+ where R8 full mode enabled by default I faced problem with moxy, when some strategies not applied to view after configuration change. After digging into the problem I found that R8 remove *Command classes which have analogs with same fields within view state class.
F.e:
data class SetImageCommand(
val imageResId: Int,
): ViewCommand(tag = "setImage", strategy = AddToEndSingleStrategy.class)
and
data class SetMaxInputLengthCommand(
val length: Int,
): ViewCommand(tag = "setMaxInputLength", strategy = AddToEndSingleStrategy.class)
One of the classes would be removed by R8, because both of them take only one Int parameter in constructor. It leads to 'overwriting' command stack by subsequent command:
setMaxInputLength after minification uses SetImageCommand class, then after configuration change instead of expected execution of both commands we get only one executed command with wrong parameters (SetImageCommand(imageResId = 10)).
Solution
We need to tell R8 keep all classes that extends ViewCommand. You can use these rules:
-keep,allowobfuscation class * extends moxy.viewstate.MvpViewState { *; }
-keep,allowobfuscation class * extends moxy.viewstate.ViewCommand { *; }
Problem
After update to AGP 8+ where R8 full mode enabled by default I faced problem with moxy, when some strategies not applied to view after configuration change. After digging into the problem I found that R8 remove
*Command
classes which have analogs with same fields within view state class. F.e:and
One of the classes would be removed by R8, because both of them take only one
Int
parameter in constructor. It leads to 'overwriting' command stack by subsequent command:setMaxInputLength
after minification usesSetImageCommand
class, then after configuration change instead of expected execution of both commands we get only one executed command with wrong parameters (SetImageCommand(imageResId = 10)
).Solution
We need to tell R8 keep all classes that extends
ViewCommand
. You can use these rules: