Pau Marzo
07/24/2024, 12:02 PMPau Marzo
07/24/2024, 12:06 PM# 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 Companion;
}
# 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
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations
-dontnote kotlinx.serialization.SerializationKt
# Keep Serializers
-keep,includedescriptorclasses class com.package.name.**$$serializer { *; }
-keepclassmembers class com.package.name.** {
*** Companion;
}
-keepclasseswithmembers class com.package.name.** {
kotlinx.serialization.KSerializer serializer(...);
}
# When kotlinx.serialization.json.JsonObjectSerializer occurs
-keepclassmembers class kotlinx.serialization.json.** {
*** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
kotlinx.serialization.KSerializer serializer(...);
}
### <https://github.com/Kotlin/kotlinx.serialization/blob/master/rules/r8.pro>
# Rule to save runtime annotations on serializable class.
# If the R8 full mode is used, annotations are removed from classes-files.
#
# For the annotation serializer, it is necessary to read the `Serializable` annotation inside the serializer<T>() function - if it is present,
# then `SealedClassSerializer` is used, if absent, then `PolymorphicSerializer'.
#
# When using R8 full mode, all interfaces will be serialized using `PolymorphicSerializer`.
#
# see <https://github.com/Kotlin/kotlinx.serialization/issues/2050>
-if @kotlinx.serialization.Serializable class **
-keep, allowshrinking, allowoptimization, allowobfuscation class <1>
### END
#-keep @kotlinx.serialization.Serializable class * {*;}
-keep @kotlinx.serialization.Serializable class **
Pau Marzo
07/24/2024, 12:06 PMChrimaeon
07/24/2024, 12:56 PMcom.package.name
in the ruleset you postet. Those should be replaced with the actual package name of your app.Pau Marzo
07/24/2024, 12:57 PMChrimaeon
07/24/2024, 12:57 PMMichael Paus
07/24/2024, 1:52 PMbuildTypes.release {
proguard {
version.set("7.5.0")
isEnabled.set(true)
optimize.set(false)
obfuscate.set(false)
configurationFiles.from(project.file("<http://compose-desktop.pro|compose-desktop.pro>"))
}
}
It’s important to enable it because that accounts for the biggest reduction in code. Optimization and obfuscation don’t contribute that much and are simply not worth the pain they are causing. And as long as Jetbrains is, e.g., still adding a 20 MB Intel library to the ARM code on macs I really don’t see a reason to squeeze out the last bit of code reduction via ProGuard optimization and obfuscation. See:
https://youtrack.jetbrains.com/issue/COMPT-3859/Intel-binary-in-ARM-library