Skip to content

大家如果遇到开启混淆后,奔溃的问题加上如下代码即可解决问题 #63

@tanranran

Description

@tanranran

奔溃代码:
`
class TestActivity : BaseViewBindingActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    title = "提交成功"
}

}
`
未奔溃代码:

`
class TestActivity : BaseViewBindingActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    title = "提交成功"
    getBinding().root.setBackgroundColor(Color.RED)
}

}
`
原因:
使用baseViewBind类的时候,如果未调用过getBinding()中的属性,在打release包时,编译器优化会优化掉泛型中的ViewBind类[因为在编译器看来该ViewBind中的类未被使用],导致找不到ViewBind类

解决办法:
-keep class * implements androidx.viewbinding.ViewBinding {*;}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions