Yassine Abou
04/28/2025, 11:42 PM⚠️
Serializer for class 'ChatCompletionRequest' is not found. Please
ensure the class is marked as '@Serializable' and the serialization
compiler plugin is applied.
I’ve already marked the ChatCompletionRequest
class as @Serializable
. I also followed advice from two StackOverflow links about similar issues (linked below), including updating Proguard rules to keep serializers. Unfortunately, nothing has fixed the problem so far.
Here are the StackOverflow threads I referenced:
1. Serializer for class not found
2. Proguard/R8 serialization issue
The full code is in my GitHub repository: https://github.com/yassineAbou/LLMSwwalkingg
04/29/2025, 12:30 AMYassine Abou
04/29/2025, 12:50 AMwwalkingg
04/29/2025, 1:05 AMYassine Abou
04/29/2025, 1:18 AMwwalkingg
04/29/2025, 2:27 AMbuildTypes.release.proguard {
version.set("7.6.0")
configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
obfuscate.set(true)
}
2. compose-desktop.pro
add below rules
# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$* Companion;
}
# Keep names for named companion object from obfuscation
# Names of a class and of a field are important in lookup of named companion in runtime
-keepnames @kotlinx.serialization.internal.NamedCompanion class *
-if @kotlinx.serialization.internal.NamedCompanion class *
-keepclassmembernames class * {
static <1> *;
}
# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}
# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
# Don't print notes about potential mistakes or omissions in the configuration for kotlinx-serialization classes
# See also <https://github.com/Kotlin/kotlinx.serialization/issues/1900>
-dontnote kotlinx.serialization.**
# Serialization core uses `java.lang.ClassValue` for caching inside these specified classes.
# If there is no `java.lang.ClassValue` (for example, in Android), then R8/ProGuard will print a warning.
# However, since in this case they will not be used, we can disable these warnings
-dontwarn kotlinx.serialization.internal.ClassValueReferences
# disable optimisation for descriptor field because in some versions of ProGuard, optimization generates incorrect bytecode that causes a verification error
# see <https://github.com/Kotlin/kotlinx.serialization/issues/2719>
-keepclassmembers public class **$$serializer {
private ** descriptor;
}
-optimizations !method/specialization/**
-dontwarn kotlinx.datetime.**
-dontwarn org.slf4j.**
-keep class org.slf4j.**{ *; }
-keep class com.sun.jna.* { *; }
-keep class * implements com.sun.jna.* { *; }
-keep class com.sun.jna.** { *; }
-keep class * implements com.sun.jna.** { *; }
### from <https://raw.githubusercontent.com/square/okhttp/master/okhttp/src/main/resources/META-INF/proguard/okhttp3.pro>
# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt and other security providers are available.
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
### from <https://github.com/auth0/Auth0.Android/blob/main/proguard/proguard-okio.pro>
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn com.squareup.okhttp.internal.Platform
### from <https://github.com/Kotlin/kotlinx.serialization/issues/2385>
-keep @kotlinx.serialization.Serializable class * {*;}
### from <https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:datastore/datastore-preferences/proguard-rules.pro;drc=ba352589a039f23c1450755ca3a76a50b9722e69?hl=zh-cn>
-keepclassmembers class * extends androidx.datastore.preferences.protobuf.GeneratedMessageLite {
<fields>;
}
### from <https://github.com/russhwolf/multiplatform-settings/blob/eca5f8c0d55420445dd562dfb827f1e0b7e925b1/sample/app-android/proguard-rules.pro>
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# <http://developer.android.com/guide/developing/tools/proguard.html>
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-dontwarn * # Suppress warnings.
Yassine Abou
04/29/2025, 3:55 AM