-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bundled proguard rules (#2092)
* added delivery of ProGuard/R8 rules along with the core artifact. * the documentation about the rules has been made more readable * added an example of rules for named companions for R8 full mode * added R8-only rules to support full mode * rules have been introduced suppressing some warnings about serialization classes Resolves #1121 Resolves #1899 Resolves #1900 Resolves #2050
- Loading branch information
Showing
4 changed files
with
107 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 | ||
|
||
# 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 `Class.forName("java.lang.ClassValue")` for caching in JVM-only, so it is an expected situation that this class is not in Android | ||
-dontwarn java.lang.ClassValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# 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, allowaccessmodification class <1> |