Android Moshi Json Converter Causes kotlin.reflect.jvm.internal.KotlinReflectionInternalError

33 Views Asked by At

I am using Moshi as Json Converter with Retrofit in Android.

When I set minifyEnabled to true, For some API calls it works, but for others it throws this Error:

This callable does not support a default call: public constructor ErrorResponse.

Note that I am using a custom NetworkResponseAdapter and NetworkResponseCall. The exception is thrown on this line in the NetworkResponseCall when I try to convert the Json response to the ErrorResponse Data class: errorConverter.convert(error).

2

There are 2 best solutions below

0
Omar Assidi On BEST ANSWER

Update!! The Solution:

It turned out I need to add the CodeGen Kapt or KSP dependency com.squareup.moshi:moshi-kotlin-codegen:1.15.0 in addition to @JsonClass(generateAdapter = true) for the Classes that use Moshi.

Details here

3
Viewed On

When you enable the minify option, the compiler replaces your class names, fields and so on. Instead of MyAdapter class, execute method and name inside model that is serialized by Moshi, they will become Abc class, adcd method and gr for field. Thies includes internal information that requires for reflection and generics.

In order to fix this, you must write set of rules in proguard-rules.pro file by default to exclude peaces of code from renaming and other operations. In practice, every popular library adds such rules itself. However with custom classes as your adapter or serialized data classes, you need to add rules manually.

Android Docs, Short Guide, ProGuard Manual