Moshi - Unable to create converter for enum class for gradle 8 and upwards

An error occurs during runtime, after updating to gradle 8.1.1 from 7.4.2: "java.lang.IllegalArgumentException: Unable to create converter for class $myEnumClass Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.reflect.Field java.lang.Class.getField(java.lang.String)' on a null object reference". I use EnumJsonAdapterFactory to parse enums that is declared on this way when creating moshi:
val moshi = Moshi.Builder().add(EnumJsonAdapterFactory).build()
Any ideas?


  • SOLUTION: I found this solution and I post it in order to help everyone who faces the same problem.
    When using EnumJsonAdapterFactory for parsing enums, you must add
    -keep class { *; }
    in of app's build.gradle. This error caused by the fact that android.enableR8.fullMode is enabled by default in gradle 8 and upwards