sumup / sumup-android-sdk

Sample App for the SumUp Android SDK
Other
101 stars 29 forks source link

Signature screen crashes on devices with API 21-25 with outdated WebView #98

Open christxph opened 4 years ago

christxph commented 4 years ago

The SignatureFragment crashes on API 21-25 devices with an old WebView version installed because of the WebViews included in the fragment_signature_view.xml layout. The stacktrace of this crash is:

Fatal Exception: android.view.InflateException: Binary XML file line #88: Error inflating class android.webkit.WebView
       at android.view.LayoutInflater.createView(LayoutInflater.java:633)
       at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
       at com.sumup.merchant.ui.Fragments.SignatureFragment.onCreateView(SignatureFragment.java:164)
       at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
       at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
       at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
       at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
       at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
       at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
       at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
       at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
       at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
       at android.os.Handler.handleCallback(Handler.java:815)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loop(Looper.java:194)
       at android.app.ActivityThread.main(ActivityThread.java:5643)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Underlying cause of the crash

The underlying cause of the crash is a bug in the AppCompat library v1.1.0 There are multiple reports for that in the Android bug tracker, e.g.:

How to fix it

We had the same issue in WebViews used in our app, but fixed it by applying the following workaround (as posted in the bug tracker: https://issuetracker.google.com/issues/141132133#comment6):

If you want to use 1.1.0 , override applyOverrideConfiguration in your activity as follows. However, this might need app restart for API 21 to 25, while switching Dark Theme to Light Theme and vice versa.

override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
   if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode == AppConstants.appContext.resources.configuration.uiMode)) {
       return
   }
   super.applyOverrideConfiguration(overrideConfiguration)
}

An easy way to fix this crash in the SumUp SDK, would be to implement the workaround in the SignatureFragment's parent Activity.

Google is also working on a workaround/fix (https://issuetracker.google.com/issues/141351441#comment23) to be included in the AppCompat SDK, but until then signature payments do not work on all affected devices.

christxph commented 4 years ago

For anyone else experiencing this: According to this AppCompat bugtracker issue upgrading to v1.2.0-alpha02 of the AppCompat library should fix this issue

implementation "androidx.appcompat:appcompat:1.2.0-alpha02"

I will keep this issue open until a non-alpha release of the AppCompat library with Google's fix is released.