Names of parameters in constructor of kotlin class are removed by proguard even with -keep

Viewed 391

I have a class with the following constructor:

class Configuration @JvmOverloads constructor(val applicationId: String, typesToAutomaticallyLoad: List<AutoLoadableType>,
                                                    val isTestMode: Boolean = false, var userId: String? = null,
                                                    private var videoNetworks: List<MDNetwork> = MDNetwork.values().toMutableList(),
                                                    private var networks: List<MDAdNetwork> = MDNetwork.values().toMutableList(),
                                                    var loadingTimeoutMs: Long = 20000) 

my proguard file:

-keep class mypackage.** {
    <init>(...);
    *;
}

with minify disabled i get:

   @JvmOverloads
   public Configuration(@NotNull String applicationId, @NotNull List typesToAutomaticallyLoad, boolean isTestMode, @Nullable String userId, @NotNull List videoNetworks, @NotNull List networks) {
      this(applicationId, typesToAutomaticallyLoad, isTestMode, userId, videoNetworks, networks, 0L, 64, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String applicationId, @NotNull List typesToAutomaticallyLoad, boolean isTestMode, @Nullable String userId, @NotNull List videoNetworks) {
      this(applicationId, typesToAutomaticallyLoad, isTestMode, userId, videoNetworks, (List)null, 0L, 96, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String applicationId, @NotNull List typesToAutomaticallyLoad, boolean isTestMode, @Nullable String userId) {
      this(applicationId, typesToAutomaticallyLoad, isTestMode, userId, (List)null, (List)null, 0L, 112, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String applicationId, @NotNull List typesToAutomaticallyLoad, boolean isTestMode) {
      this(applicationId, typesToAutomaticallyLoad, isTestMode, (String)null, (List)null, (List)null, 0L, 120, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String applicationId, @NotNull List typesToAutomaticallyLoad) {
      this(applicationId, typesToAutomaticallyLoad, false, (String)null, (List)null, (List)null, 0L, 124, (DefaultConstructorMarker)null);
   }

with minify enabled i get:

   @JvmOverloads
   public Configuration(@NotNull String var1, @NotNull List var2, boolean var3, @Nullable String var4, @NotNull List var5, @NotNull List var6) {
      this(var1, var2, var3, var4, var5, var6, 0L, 64, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String var1, @NotNull List var2, boolean var3, @Nullable String var4, @NotNull List var5) {
      this(var1, var2, var3, var4, var5, (List)null, 0L, 96, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String var1, @NotNull List var2, boolean var3, @Nullable String var4) {
      this(var1, var2, var3, var4, (List)null, (List)null, 0L, 112, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String var1, @NotNull List var2, boolean var3) {
      this(var1, var2, var3, (String)null, (List)null, (List)null, 0L, 120, (DefaultConstructorMarker)null);
   }

   @JvmOverloads
   public Configuration(@NotNull String var1, @NotNull List var2) {
      this(var1, var2, false, (String)null, (List)null, (List)null, 0L, 124, (DefaultConstructorMarker)null);
   }

So this proguard configuration keeps the class name, constructor names, but not parameter names.

How do I make it keep the parameter names too?

1 Answers

You must add @SerializedName("...") with all parameters,

data class SyncUser( @SerializedName("user") val user: User )

Related