启用 ProGuard 的签名 apk 崩溃

问题描述

我创建了一个用于接收数据的开放类:

open class Event<out T>(private val content: T) {

var hasBeenHandled = false
    private set // Allow external read but not write

/**
 * Returns the content and prevents its use again.
 */
fun getContentIfNotHandledOrReturnNull(): T? {
    return if (hasBeenHandled) {
        null
    } else {
        hasBeenHandled = true
        content
    }
}

/**
 * Returns the content,even if it's already been handled.
 */
fun peekContent(): T = content

}

但是在签名的 apk 在此导入中出错

我的 Proguard

 -ignorewarnings
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-keep public class com.vslib.base.model.Job { *; }
-keep public class com.google.android.gms.*{ public *; }
-assumenosideeffects class android.util.Log {
    public static *** d(...);
}
-keep public class * extends android.app.Service
-keep public class * extends android.content.broadcastReceiver
-keep public class * extends android.provider.Settings
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod
-keep class * extends androidx.lifecycle.viewmodel {
    <init>();
}
-keep class * extends androidx.lifecycle.Androidviewmodel {
    <init>(android.app.Application);
}
-keepattributes *Annotation*
-keepclassmembers enum androidx.lifecycle.Lifecycle$Event {
    <fields>;
}
-keep class androidx.lifecycle.* { *; }

Error LOG:

 

at com.packagename.fragment.a(SourceFile:32)
        at g.j.a.c.j.i.j.a(SourceFile:7)
        at g.j.a.c.h.i.e.onTransact(SourceFile:3)
        at android.os.Binder.transact(Binder.java:504)
        at dx.aZ(:com.google.android.gms.dynamite_mapsdynamite@210915051@21.09.15 (040408-0):2)
        at com.google.maps.api.android.lib6.impl.bj.run(:com.google.android.gms.dynamite_mapsdynamite@210915051@21.09.15 (040408-0):1)
        at android.os.Handler.handleCallback(Handler.java:836)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:203)

使用事件类时出现上述错误。如果我隐藏类它工作正常但如果启用崩溃。任何人都可以帮忙解决这个问题。还需要启用 proguard

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)