androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

ViewBinding stopped working with proguarded builds #49

Closed cristan closed 3 years ago

cristan commented 3 years ago

When I run a release build I get the following exception:

Caused by: java.lang.NoSuchMethodException: com.action.consumerapp.databinding.ActivitySplashBinding.bind [class android.view.View]
   at java.lang.Class.getMethod(Class.java:2072)
   at java.lang.Class.getMethod(Class.java:1693)
   at d.a.a.j.a.<init>(ViewBindingCache.kt:97)
   at d.a.a.j.f.a(ViewBindingCache.kt:27)
   at d.a.a.g$a.a(ActivityViewBindings.kt:38)
   at d.a.a.g$a.invoke(Unknown Source:2)
   at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.f(ViewBindingProperty.kt:59)
   at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.a(ViewBindingProperty.kt:46)
   at com.action.consumerapp.feature.splash.SplashActivity.i(Unknown Source:7)

This occurs at 'com.github.kirich1409:viewbindingpropertydelegate:1.4.3' and 'com.github.kirich1409:viewbindingpropertydelegate:1.4.4'. This doesn't happen with 'com.github.kirich1409:viewbindingpropertydelegate:1.4.2' (or 'com.kirich1409.viewbindingpropertydelegate:viewbindingpropertydelegate:1.4.2').

kirich1409 commented 3 years ago

Check version 1.4.5

alexkopenkov commented 3 years ago

I had a similar problem (v1.4.4) and in version 1.4.5 everything works well.

sandip-torinit commented 1 year ago

Getting same issue in 1.5.8.

kirich1409 commented 1 year ago

Getting same issue in 1.5.8.

Show me the stacktrace and the code with usage of ViewBinding in that place

sandip-torinit commented 1 year ago

Getting same issue in 1.5.8.

Show me the stacktrace and the code with usage of ViewBinding in that place

Here is the stacktrace.

Caused by: java.lang.NoSuchMethodException: com.ppm.pace365app.databinding.ActivitySignInBinding.bind [class android.view.View]
  at java.lang.Class.getMethod(Class.java:2072)
  at java.lang.Class.getMethod(Class.java:1693)
  at by.kirich1409.viewbindingdelegate.internal.BindViewBinding.<init>(ViewBindingCache.kt:116)
  at by.kirich1409.viewbindingdelegate.internal.ViewBindingCache.getBind$com_github_kirich1409_ViewBindingPropertyDelegate_core(ViewBindingCache.kt:29)
  at by.kirich1409.viewbindingdelegate.ReflectionActivityViewBindings$viewBinding$2.invoke(ActivityViewBindings.kt:61)
  at by.kirich1409.viewbindingdelegate.ReflectionActivityViewBindings$viewBinding$2.invoke(ActivityViewBindings.kt:60)
  at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:102)
  at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:71)

When I tried 1.4.5, it was working fine, but getting the issue in 1.5.8.

Update: Hey, just found that it is working on 1.5.6 too. But I'm still getting crash on 1.5.8.

kirich1409 commented 1 year ago

I've just found out the problem. Will be fixed in next release. As temporary solution please add to you ProGuard config next lines

-keep,allowoptimization class * implements androidx.viewbinding.ViewBinding {
    public static *** bind(android.view.View);
    public static *** inflate(...);
}
sandip-torinit commented 1 year ago

-keep,allowoptimization class * implements androidx.viewbinding.ViewBinding { public static bind(android.view.View); public static inflate(...); }

This worked. Thanks

al-t commented 3 months ago

There is a similar crash in 1.5.9 as well:

Caused by: java.lang.NoSuchMethodException: my.project.databinding.MiisFragmentShowcaseBinding.bind [class android.view.View]
    at java.lang.Class.getMethod(Class.java:2103)
    at java.lang.Class.getMethod(Class.java:1724)
    at by.kirich1409.viewbindingdelegate.internal.BindViewBinding.<init>(ViewBindingCache.kt:14)
    at by.kirich1409.viewbindingdelegate.ReflectionFragmentViewBindings$viewBinding$3.invoke(FragmentViewBindings.kt:28)
    at by.kirich1409.viewbindingdelegate.LifecycleViewBindingProperty.getValue(ViewBindingProperty.kt:8)
    at by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue(FragmentViewBindings.kt:3)
    at by.kirich1409.viewbindingdelegate.FragmentViewBindingProperty.getValue(FragmentViewBindings.kt:2)
    at my.project.ShowcaseFragment.getBinding(ShowcaseFragment.kt:8)
    ...

Adding the proguard rules helps:

-keep,allowoptimization class * implements androidx.viewbinding.ViewBinding {
    public static *** bind(android.view.View);
    public static *** inflate(...);
}