【问题标题】:Getting crash while take up singed apk with proguard enabled in my cases在我的情况下,在启用 proguard 的情况下占用 singed apk 时发生崩溃
【发布时间】:2021-04-01 09:17:46
【问题描述】:

我正在使用实时数据观察概念——当隐藏这条线并开始构建时,它工作正常。如果我启用以下代码获取

  viewModel.loadValue.observe(viewLifecycleOwner, Observer<String?> {
        toSelectPlaceSearchValue(it.toString())
    })

得到以下错误

  at .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)
    at android.app.ActivityThread.main(ActivityThread.java:6293)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1065)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:926)

我的 Proguard 文件 txt

-keep class androidx.lifecycle.* { *; }

【问题讨论】:

    标签: android proguard android-livedata


    【解决方案1】:

    我建议你在你的 proguard 规则中添加这两行,它肯定会起作用。

    -keep class * extends androidx.lifecycle.ViewModel 
      {
        <init>();
      }
    -keep class * extends androidx.lifecycle.AndroidViewModel 
      {
        <init>(android.app.Application);
      }
    

    查看link 以供参考。

    【讨论】:

    • open class Event(private val content: T) { /** * 返回内容,即使它已经被处理过。 */ fun peekContent(): T = content } 这是导入 -- com.fragment.a(SourceFile:32) 处的类出现错误 -- gjachieonTransact(SourceFile:3) 处 gjacjija(SourceFile:7) 处的导入类得到强制关闭
    【解决方案2】:

    请试试这个 -keep class androidx.lifecycle.** { *; }

    【讨论】:

    • 试过了,但我在 Open class Event import 中遇到错误 .. open class Event(private val content: T) { var hasBeenHandled = false private set // 允许外部读取但不允许写入/** * 返回内容并阻止其再次使用。 */ 有趣的 getContentIfNotHandledOrReturnNull(): T? { return if (hasBeenHandled) { null } else { hasBeenHandled = true content } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多