'Expo + Stripe CardFormField crashes on Android build

I am implementing Stripe in my React Native (Expo) app. When testing it out with ExpoGO it works well, and so does the iOS build via Testflight. However, after building the app for Android it will crash whenever the CardFormField component (provided by Stripe) is rendered.

I have logged the errors in Sentry, and this is where it goes wrong:

Binary XML file line #5 in [censored]:layout/stripe_card_form_view: Error inflating class com.google.android.material.card.MaterialCardView

IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

I then found this, here:

In order to use CardForm component, you need to install and configure Material Components theme in your app.

I do however fail to find information on how I am expected to comply with this requirement using Expo. Do anyone have any ideas?

I am using:

  • expo 43.0.3
  • @stripe/stripe-react-native 0.2.2
  • App is built with eas
  • I use expo (not an ejected app)

Thanks in advance for any help.



Solution 1:[1]

With Expo you have a choice between managed vs. bare workflows. In order to access the build.gradle and styles.xml files to configure the Material Components theme you need to switch to a bare workflow. You need to use expo eject to create the native Android files in question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Justin Michael