stripe-react-native icon indicating copy to clipboard operation
stripe-react-native copied to clipboard

Android Build Error: `ReadableMap?` Nullability Issue in Stripe React Native SDK (RN 0.80+)

Open erenkeskin opened this issue 5 months ago • 0 comments

Describe the bug When using the latest version of @stripe/stripe-react-native on Android with React Native 0.80+, the build fails due to Kotlin nullability type mismatch errors. Specifically, some internal view manager functions expect a non-null ReadableMap, but the upstream Dynamic.asMap() method may return null. As a result, the compiler throws an error like: Argument type mismatch: actual type is ‘ReadableMap?’, but ‘ReadableMap’ was expected.

This issue started after upgrading to the latest Stripe SDK and React Native versions.

To Reproduce Steps to reproduce the behavior:

  1. Upgrade to @stripe/stripe-react-native@latest (tested on v0.48.0).
  2. Use React Native 0.80.x+ (or a version where Dynamic.asMap() returns nullable).
  3. Run npx react-native run-android or try to build via Gradle.
  4. Observe the following error in the build logs: e: …/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt:57:51 Argument type mismatch: actual type is ‘ReadableMap?’, but ‘ReadableMap’ was expected.

Expected behavior The project should build successfully. The Stripe SDK should correctly handle nullable values returned from Dynamic.asMap() by checking for null and failing gracefully, or providing a helpful error message.

Screenshots If applicable, you can see the error in the build output:

e: …/EmbeddedPaymentElementViewManager.kt:57:51 Argument type mismatch: actual type is ‘ReadableMap?’, but ‘ReadableMap’ was expected. e: …/EmbeddedPaymentElementViewManager.kt:74:49 Argument type mismatch: actual type is ‘ReadableMap?’, but ‘ReadableMap’ was expected. e: …/pushprovisioning/AddToWalletButtonManager.kt:67:26 Argument type mismatch: actual type is ‘ReadableMap?’, but ‘ReadableMap’ was expected.

Desktop

  • OS: macOS Sonoma 14.5
  • Node: 22.10.0
  • NPM: 11.0

Smartphone

  • Device: [Any Android device or emulator]
  • OS: Android 13/14

Additional context

  • The problem is due to upstream changes in React Native, where Dynamic.asMap() now returns a nullable type.
  • The SDK currently expects ReadableMap (non-nullable), but doesn’t perform a null check before passing the value to functions.
  • This breaks Android builds out of the box on newer React Native versions.
  • Temporary workaround: patch all instances of cfg.asMap() with null checks in the relevant files (e.g., EmbeddedPaymentElementViewManager.kt, AddToWalletButtonManager.kt) before passing to other functions, e.g.:
    val readableMap = cfg.asMap()
    if (readableMap == null) return // or handle the error
    ...
    

erenkeskin avatar Jun 16 '25 20:06 erenkeskin