From 1b0accd69fecaf24b928d9593aa1e046069786f8 Mon Sep 17 00:00:00 2001 From: Sergey Shanshin Date: Mon, 25 Nov 2024 17:06:47 +0300 Subject: [PATCH] Fixed keeping INSTANCE field and serializer function for serializable objects in R8 full mode (#2865) Details https://issuetracker.google.com/issues/379996140 Fixes #2861 --- rules/r8.pro | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rules/r8.pro b/rules/r8.pro index ad5dd305cc..879917c118 100644 --- a/rules/r8.pro +++ b/rules/r8.pro @@ -10,3 +10,16 @@ -if @kotlinx.serialization.Serializable class ** -keep, allowshrinking, allowoptimization, allowobfuscation, allowaccessmodification class <1> + + +# Rule to save INSTANCE field and serializer function for Kotlin serializable objects. +# +# R8 full mode works differently if the instance is not explicitly accessed in the code. +# +# see https://github.com/Kotlin/kotlinx.serialization/issues/2861 +# see https://issuetracker.google.com/issues/379996140 + +-keepclassmembers @kotlinx.serialization.Serializable class ** { + public static ** INSTANCE; + kotlinx.serialization.KSerializer serializer(...); +}