nambicompany / expandable-fab

A highly customizable 'speed dial' FloatingActionButton implementation.
https://nambicompany.github.io/expandable-fab/
MIT License
200 stars 21 forks source link

Caused by java.lang.NoSuchMethodError #37

Closed kartik0198 closed 3 years ago

kartik0198 commented 3 years ago

My app is crashing on startup when I updated my library version to 1.2.0 Please see the following logs. compileSdkVersion = 31 minSdkVersion = 21 targetSdkVersion = 30

Fatal Exception: android.view.InflateException
Binary XML file line #150: Binary XML file line #36: Error inflating class com.nambimobile.widgets.efab.ExpandableFab
Caused by android.view.InflateException
Binary XML file line #36: Error inflating class com.nambimobile.widgets.efab.ExpandableFab

Caused by java.lang.reflect.InvocationTargetException
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
androidx.databinding.DataBindingUtil.inflate (DataBindingUtil.java:95)
com.niyotail.consumer.ui.base.BaseFragment.onCreateView (BaseFragment.java:48)
androidx.fragment.app.Fragment.performCreateView (Fragment.java:2963)
androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:246)
com.niyotail.consumer.ui.main.MainActivity.onStart (MainActivity.java:331)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1391)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

Caused by java.lang.NoSuchMethodError
No virtual method setPadding(IIII)V in class Landroid/graphics/drawable/GradientDrawable; or its super classes (declaration of 'android.graphics.drawable.GradientDrawable' appears in /system/framework/framework.jar)
com.nambimobile.widgets.efab.Label.<init> (Label.java:274)
com.nambimobile.widgets.efab.ExpandableFab.<init> (ExpandableFab.java:243)
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
androidx.databinding.DataBindingUtil.inflate (DataBindingUtil.java:95)
com.niyotail.consumer.ui.base.BaseFragment.onCreateView (BaseFragment.java:48)
androidx.fragment.app.Fragment.performCreateView (Fragment.java:2963)
androidx.appcompat.app.AppCompatActivity.onStart (AppCompatActivity.java:246)
com.niyotail.consumer.ui.main.MainActivity.onStart (MainActivity.java:331)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1391)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)`
kabumere commented 3 years ago

@kartik0198,

Thanks for that. Just tested and reproduced.

Context (in case you're curious): When the library targeted SDK 28, setPadding did not exist on GradientDrawable (which our Labels use for backgrounds). So when we called setPadding previously, we were setting it on the TextView itself (which Label derives from). It seems that Android added a setPadding on GradientDrawables in SDK 29 however. So now that the library targets SDK 30 as of the last update, it tries to use the newer setPadding method that does not exist on devices below 29. Unintended consequence of the new target version. Working on a fix right now and will make sure I test on multiple Android versions before publishing. Will update this thread when it's published.

kartik0198 commented 3 years ago

Thanks for the update and yes it was unintended consequence of the new target version. You may test with strict mode's detectNonSdkApiUsage() to avoid bugs like these in future. :)

kabumere commented 3 years ago

Thanks for the update and yes it was unintended consequence of the new target version. You may test with strict mode's detectNonSdkApiUsage() to avoid bugs like these in future. :)

I don't think this would have caught the issue at hand. That Strict Mode policy only catches use of illegal non-SDK APIs through reflection, correct? Whereas for this bug, there was just ambiguity on which legal SDK API to use (a new method of the same name just so happened to be added to a class, so we were unintentionally using this new legal method instead of an old legal method).

kabumere commented 3 years ago

Hey @kartik0198,

Bug fixed (if curious, this was the only change needed to the Label class). I tested all the way down to SDK 19 (some of those tests were done on emulators though, I don't have physical devices running old Android versions unfortuntately).

v1.2.1 is already pushed to master branch, and should be available via Maven Central soon. It should fix your problem, but let me know if it doesn't. Thanks for spotting this!

kartik0198 commented 3 years ago

Sure, I will let you know! Thanks.