Skip to main content

React Native

Instructions for installing Purchases SDK for React Native

AIAsk AIChatGPTClaude

What is RevenueCat?

RevenueCat provides a backend and SDKs that wrap StoreKit, Google Play Billing, the Amazon Appstore, the Samsung Galaxy Store, and RevenueCat Web Billing to make implementing in-app and web purchases and subscriptions easy. With our SDK, you can build and manage your app business on any platform without having to maintain IAP infrastructure. You can read more about how RevenueCat fits into your app or you can sign up free to start building.

Installation

Release

Make sure that the deployment target for iOS is at least 13.4 and Android is at least 6.0 (API 23) as defined here.

React Native package

Purchases for React Native can be installed either via npm or yarn.

We recommend using the latest version of React Native, or making sure that the version is at least greater than 0.64.

Option 1.1: Using auto-linking

Recent versions of React Native will automatically link the SDK, so all that's needed is to install the library.

npm install --save react-native-purchases

Option 1.2: Manual linking

npm install --save react-native-purchases

After that, you should link the library to the native projects by doing:

react-native link react-native-purchases

Using Expo

Use Expo to rapidly iterate on your app by using JavaScript/TypeScript exclusively, while letting Expo take care of everything else.

See Using RevenueCat with Expo to get started.

Set the correct launchMode for Android

Depending on your user's payment method, they may be asked by Google Play to verify their purchase in their (banking) app. This means they will have to background your app and go to another app to verify the purchase. If your Activity's launchMode is set to anything other than standard or singleTop, backgrounding your app can cause the purchase to get cancelled. To avoid this, set the launchMode of your Activity to standard or singleTop in your Android app's AndroidManifest.xml file, like so:

<activity 
android:name="com.your.Activity"
android:launchMode="standard" /> <!-- or singleTop -->

You can find Android's documentation on the various launchMode options here.

Amazon Appstore for Android

To build a React Native Android app for the Amazon Appstore, configure the SDK with your Amazon Appstore API key and set useAmazon to true:

import Purchases from 'react-native-purchases';

Purchases.configure({
apiKey: <revenuecat_project_amazon_api_key>,
useAmazon: true,
});

Adding support for Amazon also requires adding a .pem public key to your project. You can configure this key by following Amazon's guide here.

Due to some limitations, RevenueCat will only validate purchases made in production or in Live App Testing and won't validate purchases made with the Amazon App Tester.

Galaxy Store for Android

Galaxy Store support is available in React Native SDK versions 10.3.0 and above.

To build a React Native Android app for the Galaxy Store, install the Galaxy Store add-on package in addition to react-native-purchases.

npm install --save react-native-purchases-store-galaxy

Configure the SDK with your Galaxy Store API key and set store to GALAXY:

import Purchases from 'react-native-purchases';
import { GALAXY_BILLING_MODE } from 'react-native-purchases-store-galaxy';

Purchases.configure({
apiKey: <revenuecat_project_galaxy_api_key>,
store: 'GALAXY',
// Optional. Defaults to PRODUCTION.
galaxyBillingMode: GALAXY_BILLING_MODE.TEST,
});

galaxyBillingMode is optional and defaults to GALAXY_BILLING_MODE.PRODUCTION. Use GALAXY_BILLING_MODE.TEST for test purchases or GALAXY_BILLING_MODE.ALWAYS_FAIL to test failure scenarios. Only use production mode when submitting your app for beta or production distribution.

Test purchases for the Galaxy Store can only be made on a physical Galaxy device signed in with a Samsung account. The Galaxy Store does not support making test purchases in emulators.

Before testing purchases, make sure you have also set up your Galaxy Store app and create Galaxy Store products.

Import Purchases

You should now be able to import Purchases.

import Purchases from 'react-native-purchases';
📘Include BILLING permission for Android projects

Don't forget to include the BILLING permission in your AndroidManifest.xml file

<uses-permission android:name="com.android.vending.BILLING" />
📘Enable In-App Purchase capability for your iOS project

Don't forget to enable the In-App Purchase capability for your project under Project Target -> Capabilities -> In-App Purchase

Android Build Issues

R8 Dependencies Conflict

If you encounter build failures related to R8 (Android's code shrinker) when using react-native-purchases-ui, you may see errors like:

Execution failed for task ':app:mergeExtDexDevDebug'.
> Could not resolve all files for configuration ':app:devDebugRuntimeClasspath'.

This issue occurs due to a bug in earlier versions of Android Gradle Plugin (AGP) that affects R8 dependency resolution. To fix this, add the following to your project-level build.gradle file (not app/build.gradle):

buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:8.1.44")
}
}

This solution forces the use of a specific R8 version that resolves the dependency conflicts. For more details, see the Google Issue Tracker.

React Native Web Configuration

RevenueCat's React Native SDK supports web platforms, allowing you to manage subscriptions across React Native web, mobile, and desktop apps using the same SDK.

Web Product Configuration

To enable web purchases in your React Native app, you'll need to configure products using a RevenueCat Web Billing app.

  1. Create a Web Billing App in your RevenueCat project dashboard
  2. Configure your products for web purchases

For detailed instructions on setting up web products and configuring Web Billing, see the Web Billing Overview.

📘Web Billing vs In-App Purchases

Web Billing is RevenueCat's billing engine for web purchases, which uses Stripe as the payment processor. This is separate from iOS/Android in-app purchases but integrates with the same RevenueCat entitlements system, allowing unified subscription management across platforms.

Current Limitations

When using the React Native SDK on web, keep in mind the following:

  • Web Billing Required: Web purchases require RevenueCat Web Billing setup. Native iOS/Android in-app purchases cannot be processed through the web platform.
  • Payment Processing: Web Billing purchases use Stripe as the payment processor through RevenueCat Web Billing.
  • Customer Portal: Users can manage their web subscriptions through the RevenueCat-provided customer portal.
  • Platform Separation: Web products must be configured separately from iOS/Android products in the RevenueCat dashboard, though entitlements can be shared across platforms.
  • User Identity: For unified cross-platform subscriptions, ensure you're using the same appUserID across web and mobile platforms.
  • Unsupported operations: There are some unsupported operations. Mainly operations getProducts, purchaseProduct or restorePurchases won't work on web environments.

Next Steps

Was this page helpful?