B3nedikt/ViewPump

viewpump:4.0.8 crashes if obfuscation is enabled

Closed this issue · 1 comments

Hi. It seems after B3nedikt/restring#96 fixes (view pump version dev.b3nedikt.viewpump:viewpump:4.0.8)
there is new crashes appears when app use custom view and obfuscation is enabled:

buildTypes {
        getByName("debug") {
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
        }
    }
class TESTWebView : WebView {
    
    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )
}

then on app started:

java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.b3nedikt.restring.example/dev.b3nedikt.restring.example.MainActivity}: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1

if view looks like:

class TESTWebView : WebView {

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
        context,
        attrs,
        defStyle
    )
}

crash is

     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: java.lang.NoSuchMethodException: dev.b3nedikt.restring.example.TESTWebView.<init> [class android.content.Context, interface android.util.AttributeSet]

or

class TESTWebView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyle: Int = 0
) : WebView(context, attrs, defStyle)
     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: android.view.InflateException: Binary XML file line #2 in dev.b3nedikt.restring.example:layout/activity_main: Error inflating class dev.b3nedikt.restring.example.TESTWebView
     Caused by: java.lang.IllegalArgumentException: Wrong number of arguments; expected 3, got 2

Fixed with version 4.0.9.
The first view you describe will still crash though, you need to add the two argument constructor to inflate it from XML. Or just use the @jvmoverloads annotation on the three argument constructor as in your second example, and everything will get generated for you correctly ;)