Android
What is RevenueCat?
RevenueCat provides a backend and a wrapper around StoreKit and Google Play Billing to make implementing in-app 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.
Android
Installation
Purchases for Android (Google Play and Amazon Appstore) is available on Maven and can be included via Gradle.
- Groovy
implementation 'com.revenuecat.purchases:purchases:7.0.0'
Import Purchases
You should now be able to import Purchases
.
- Java
import com.revenuecat.purchases.CustomerInfo;
import com.revenuecat.purchases.Entitlement;
import com.revenuecat.purchases.Offering;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.models.Period;
import com.revenuecat.purchases.models.Price;
import com.revenuecat.purchases.models.StoreProduct;
Configure Proguard (Optional)
We are adding Proguard rules to the library so you don't need to do anything. If you have any issues finding classes in our SDK, try adding -keep class com.revenuecat.purchases.** { *; }
to your Proguard configuration.
Purchases uses AndroidX App Startup under the hood. Make sure you have not removed the androidx.startup.InitializationProvider
completely in your manifest. If you need to remove specific initializers, such as androidx.work.WorkManagerInitializer
, set tools:node="merge"
on the provider, and tools:node="remove"
on the meta-data of the initializer you want to remove.
- AndroidManifest.xml
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
Set the correct launchMode
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 AndroidManifest.xml
file, like so:
- AndroidManifest.xml
<activity
android:name="com.your.Activity"
android:launchMode="standard" /> <!-- or singleTop -->
You can find Android's documentation on the various launchMode
options here.
Amazon
Additional Dependencies
Add a new dependency to the build.gradle apart from the regular purchases
dependency. These new dependencies have the classes needed to use Amazon IAP:
- Groovy
implementation 'com.revenuecat.purchases:purchases:7.0.0'
implementation 'com.revenuecat.purchases:purchases-store-amazon:7.0.0'
Add Amazon public key
Adding support for Amazon 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.
Next Steps
- Now that you've installed the Purchases SDK in your Android app, get started by configuring an instance of Purchases