Skip to content

Commit 4667a18

Browse files
authored
Fixed proguard rules for obfuscation to work correctly (#2983)
The current rules only apply if the companion class is called `Companion`. If obfuscation is triggered, the rule does not work and the static `Companion` field is not kept, which breaks the lookup of a companion. A rule has also been added that preserves the named companion class name and field, as they must match to correctly search for the named companion in runtime. Fixes #2976
1 parent 288f73c commit 4667a18

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

rules/common.pro

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
33
-if @kotlinx.serialization.Serializable class **
44
-keepclassmembers class <1> {
5-
static <1>$Companion Companion;
5+
static <1>$* Companion;
6+
}
7+
8+
# Keep names for named companion object from obfuscation
9+
# Names of a class and of a field are important in lookup of named companion in runtime
10+
-keepnames @kotlinx.serialization.internal.NamedCompanion class *
11+
-if @kotlinx.serialization.internal.NamedCompanion class *
12+
-keepclassmembernames class * {
13+
static <1> *;
614
}
715

816
# Keep `serializer()` on companion objects (both default and named) of serializable classes.

0 commit comments

Comments
 (0)