acefalobi / android-stepper

A library for creating a wizard-like step-through user interface that uses navigation components and menus for displaying steps with advanced customization.
Apache License 2.0
325 stars 38 forks source link

Crash on TextView.setTextAppearance (was added in API23) #15

Closed mspnr closed 3 years ago

mspnr commented 3 years ago

Problem

If running the test app on a device with API lower than 23, the following crash appears: Caused by: java.lang.NoSuchMethodError: No virtual method setTextAppearance(I)V in class Landroid/widget/TextView; or its super classes (declaration of 'android.widget.TextView' appears in /system/framework/framework.jar:classes2.dex)

Cause

The error is caused by one of these lines:

https://github.com/acefalobi/android-stepper/blob/b7c39b496ef673fbd2765f8a70ba99327c578f5d/stepper/src/main/java/com/aceinteract/android/stepper/menus/tab/TabNumberedStepperMenu.kt#L55

https://github.com/acefalobi/android-stepper/blob/b7c39b496ef673fbd2765f8a70ba99327c578f5d/stepper/src/main/java/com/aceinteract/android/stepper/menus/tab/TabNumberedStepperMenu.kt#L180

The problem is, that the used method setTextAppearance appeared only in API23: https://developer.android.com/reference/android/widget/TextView#setTextAppearance(int)

Solution

To resolve the error minimum SDK should be rasied to 23:

https://github.com/acefalobi/android-stepper/blob/b7c39b496ef673fbd2765f8a70ba99327c578f5d/buildSrc/src/main/java/BuildConfiguration.kt#L6

Or setTextAppearance should be wrapped into the following check:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
  setTextAppearance(context, textAppearance)
else
  setTextAppearance(textAppearance)
acefalobi commented 3 years ago

Thank you very much for this. You can make a PR for this using the second solution. If you're unable to, I'll try to do one before the week runs out.