Recently ran into an issue with library, which uses moshi to create runtime TypeAdapter for serialization/deserialization. The library seems to work fine with R8 disabled, but after enabling it I ran into an error message:
Fatal Exception: java.lang.IllegalArgumentException: Cannot serialize Kotlin type org.walletconnect.impls.WCSessionStore$State. Reflective serialization of Kotlin classes without using kotlin-reflect has undefined and unexpected behavior. Please use KotlinJsonAdapterFactory from the moshi-kotlin artifact or use code gen from the moshi-kotlin-codegen artifact.
for class org.walletconnect.impls.WCSessionStore$State
for java.util.Map<java.lang.String, org.walletconnect.impls.WCSessionStore$State>
The solution seems to be defining keepclass
R8 rule and it works.
But, prior to adding R8 rule, what bothers me is that if I decompile the minified binary I can see that the class in question (WCSessionStore$State
) is not minified at all and I can clearly see that it's referenced when constructing the adapter:
public final class C12848a implements WCSessionStore {
public C12848a(File file, C10727r rVar) {
C11124p.m43616g(file, "storageFile");
C11124p.m43616g(rVar, "moshi");
this.f32438c = file;
this.f32436a = rVar.mo25906d(C10747u.m42144j(Map.class, String.class, WCSessionStore.State.class));
.
.
.
public interface WCSessionStore {
public State(Session$Config session$Config, Session$PeerData session$PeerData, Session$PeerData session$PeerData2, Long l, String str, List list, Long l2) {}
.
.
.
Also worth noting would be, that I'm running android.enableR8.fullMode=true
Is this expected behavior? Is the R8 rule the only way to get around this?