After upgrading my Stripe implementation, the CardInputWidget no longer appears in my app.
Error:
Error inflating class com.stripe.android.view.CardInputWidget
Gradle implementation:
implementation 'com.stripe:stripe-android:16.9.0'
XML Code for Payment Dialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fitsSystemWindows="false">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:padding="8dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/card_outline_stripe" />
<com.example.dev.customs.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="@string/enter_your_payment_method"
android:textSize="20sp"
app:fontTextView="MuseoSans-900" />
<com.stripe.android.view.CardInputWidget
android:id="@+id/dialogue_edit_payment_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="ltr"
android:layout_marginTop="5dp"
android:padding="3dp"
android:background="@drawable/bg_stripe_payment"
android:textDirection="ltr" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp">
<Button
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@string/label_submit"
android:padding="3dp"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="@color/gradient_blue_1"
android:background="@drawable/btn_submit_bg"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
Code:
btnStartPlan.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
showPaymentDialog();
}
});
dialog.setContentView(R.layout.dialog_payment);
I've searched for solutions but haven't found anything that works. Any ideas on what might be causing this issue?
The issue arises from a compatibility problem between certain versions of androidx.appcompat:appcompat and Stripe's Android SDK.
Cause:
Updating androidx.appcompat:appcompat to version 1.3.0 or 1.4.0-alpha02 causes the CardInputWidget to fail to inflate properly, leading to the crash.
Solution:
Updating the Stripe dependency to com.stripe:stripe-android:16.10.2 resolves this issue.
I reported this issue on Stripe's GitHub repository, and they worked on a fix. For more details, you can check the GitHub issue #3770.
Steps to Fix:
Gradle:
implementation 'com.stripe:stripe-android:16.10.2'
implementation 'androidx.appcompat:appcompat:1.3.1' // or later