android 即使使用-keep,proguard也会删除Kotlin类的构造函数中的参数名称

thtygnil  于 2023-11-15  发布在  Android
关注(0)|答案(2)|浏览(130)

我有一个带有以下构造函数的类:

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)

字符串
我的proguard文件:

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


与minify禁用我得到:

@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);
   }


如果minify使能,我得到:

@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);
   }


所以这个proguard配置保留了类名、构造函数名,但没有参数名。
如何让它也保留参数名?

6tqwzwtp

6tqwzwtp1#

您必须添加@SerializedName(“...”)和所有参数,
数据类SyncUser(@SerializedName(“user”)瓦尔user:User)

ukqbszuj

ukqbszuj2#

这都是关于Kotlin元数据的。我在这里建议两件事:

  • 为ProGuard/R8的元数据文件添加规则:
-keep class kotlin.Metadata
    -keep,allowobfuscation class kotlin.Metadata { *; }

字符串

相关问题