You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Encountering a weird bug with debug variant that has minify and shrink enable. The serialization from JSON string to Kotlin data class works when ProGuard and R8 is enable.
Gradle
buildTypes {
debug {
isMinifyEnabled = true // MOSHI FAIL IF REMOVED
isShrinkResources = true // MOSHI FAIL IF REMOVED
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
) // MOSHI FAIL IF REMOVED
configure<CrashlyticsExtension> {
// No need during development, enabling it also prevents Gradle to work offline
mappingFileUploadEnabled = false
}
signingConfig = signingConfigs.getByName("debug")
}
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}
ProGuard Rules:
# Moshi
-keepclasseswithmembers class * {
@com.squareup.moshi.* <methods>;
}
Kotlin data class
object AppConfig {
@Keep
data class Remote(
val someConfigParam: String = ""
) {
/**
* Required properties or fields of this data class, can be use for quick checking using any() with specified predicate
* @see Iterable.any(predicate: (T) -> Boolean)
* */
val requiredProperties
get() = listOf(
someConfigParam
)
}
}
Object
object AppConfig {
@Keep
data class Remote(
val sampleProp: String = DEFAULT_VALUE_STRING
)
}
Caller
// Convert JSON String to this data class
parser.fromJsonString<AppConfig.Remote>(jsonString, AppConfig.Remote::class.java)
java.lang.IllegalArgumentException: Cannot serialize Kotlin type com.sample.app.utils.AppConfig$Remote. 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.
AGP: 8.2.2
Gradle: 8.2
Moshi and Moshi Codegen: 1.15.0
The text was updated successfully, but these errors were encountered:
It works if @JsonClass(generateAdapter = true) was added below @Keep annotation. What I don't get is if I enable the R8 and ProGuard in debug variant then it works even without @JsonClass annotation.
Encountering a weird bug with debug variant that has minify and shrink enable. The serialization from JSON string to Kotlin data class works when ProGuard and R8 is enable.
Gradle
ProGuard Rules:
Kotlin data class
Object
Caller
Parser implementation
Exception
AGP: 8.2.2
Gradle: 8.2
Moshi and Moshi Codegen: 1.15.0
The text was updated successfully, but these errors were encountered: