For the following Proguard rule(take Kotlin Serialization)
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}
Here what is the meaning of -if
in context with the above rule? I tried looking into official proguard documentation but couldn't find any info around that
I wrote those ProGuard rules. :) The pull request discussion about these changes may provide relevant background.
I understand your confusion, the ProGuard rules documentation is quite sparse.
-if
class_specificationSpecifies classes and class members that must be
present
to activate the subsequent keep option (-keep
,-keepclassmembers
,...). The condition and the subsequent keep option can share wildcards and references to wildcards. For example, you can keep classes on the condition that classes with related names exist in your project, with frameworks like Dagger and Butterknife.
As written in the comments of the rules you copied this from:
# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
...
So, -if @kotlinx.serialization.Serializable class **
should be read as: for all classes which have the @Serializable
annotation applied (i.e., "serializable classes"). The <1>
in -keepmembers
subsequently refers to the **
wildcard, i.e., the fully-qualified class name.