How to Add Subscriptions and Free Trials to a Flutter Android App With RevenueCat
· 21 min read
We recently added paid subscriptions with a free trial to our Flutter app on Google Play, with RevenueCat handling the billing. Users pick a monthly or yearly plan, start with a free trial, and only get charged if they keep the subscription after the trial ends.
This article walks through every step we took on Android, in the order we took them. Three problems cost us the most time, and each one gets its own section:
- Google Play won't let you create a subscription until you've uploaded a build.
- Our Google Cloud organization blocked the service account key that RevenueCat needs.
- Installing a debug build on a phone that already had the Play version failed with a signature error.
If you're building the same thing, you can follow along step by step. I've written a companion article for the App Store, and the Flutter code is shared between the two.
Before you start, you'll need:
- A Google Play developer account, with your app already created in Play Console.
- A RevenueCat account. The free tier is enough to get started.
- A Flutter app with a release signing key set up, so you can build a signed
.aab.
- Access to Google Cloud Console with a Google account.
- An Android phone signed in to a Google account you can use for testing.
Three systems are involved. Google Play takes the money, RevenueCat keeps track of who has paid, and your app asks RevenueCat whether to unlock the paid features.
- Google Play Billing shows the payment sheet, charges the user, runs the free trial and renews the subscription. It's the only one of the three that touches money.
- RevenueCat sits between Google Play and your app. It checks every purchase with Google, tracks each subscriber's state (in trial, active, cancelled or expired), and gives your app a single answer: does this user have access?
- Your app uses RevenueCat's Flutter SDK,
purchases_flutter, to show the plans, start a purchase and read that answer.
How the app, Google Play and RevenueCat work together
Notice that the app never asks Google Play whether a user has paid. It asks RevenueCat, which has already checked with Google and keeps hearing about renewals and cancellations.
You could talk to Google Play Billing directly, but then you'd also need your own server to verify purchases and listen for renewals and cancellations. RevenueCat does that part for you, and the same code works for the App Store.
RevenueCat uses three terms that come up throughout this article:
| Term |
What it is |
Our example |
| Product |
One thing a store sells, with a price and a billing period. On Google Play, it's a subscription plus a base plan |
pro:monthly, pro:yearly |
| Entitlement |
The access a product unlocks. The app checks this, never the product |
pro |
| Offering |
The set of products your paywall shows, grouped into packages. You can change it from the dashboard without releasing a new version |
Monthly and Annual packages |
Your app should always check the entitlement, not the product. That way, if you add a weekly plan or a discount later, the app code doesn't change, because the new product unlocks the same entitlement.
Google Play won't let you create a subscription until your app has an uploaded build that requests the billing permission. If you open Monetize → Products → Subscriptions on a fresh app, you'll see a message asking you to upload a build first.
You don't have to add the billing permission yourself. The purchases_flutter package adds com.android.vending.BILLING to your app's manifest when Flutter builds it.
-
Add the RevenueCat packages to pubspec.yaml and run flutter pub get. These are the versions we used; check pub.dev for the current ones:
dependencies:
purchases_flutter: ^10.13.2
purchases_ui_flutter: ^10.13.2
-
Raise the build number in pubspec.yaml. The part after the + becomes Android's version code, and Play rejects any upload with a version code it has already seen. For example, change 1.1.0+13 to 1.1.0+14.
-
Build a signed release bundle:
flutter build appbundle --release
The bundle ends up in build/app/outputs/bundle/release/app-release.aab.
-
In Play Console, go to Testing → Internal testing → Create release, upload the .aab and roll it out.
-
Under Internal testing → Testers, add your testers' email addresses and copy the opt-in link. You'll need it in Step 7.
Before you upload, check which key signed the bundle. If your release signing config is missing, Flutter quietly signs the release build with the debug key, and Play rejects it. This command shows the certificate:
keytool -printcert -jarfile build/app/outputs/bundle/release/app-release.aab
The Owner line should show your company, not Android Debug.
Also, this first build doesn't need to work. Its only job is to unlock product creation. Ours crashed on launch, because the app checks for a RevenueCat key at startup and we didn't have the Android key yet (I'll explain that check in Step 6). Since no tester installed it, that didn't matter.
On Google Play, a free trial isn't a setting on the subscription. It's an offer, attached to a base plan, which is attached to the subscription. Once these three levels make sense, the rest of Play Console gets much easier to follow.
| Level |
What it holds |
Example |
| Subscription |
A name and a permanent product ID |
pro |
| Base plan |
A billing period, prices per country, and whether it renews |
monthly (1 month), yearly (1 year) |
| Offer |
A discount or free trial on one base plan, with rules for who can get it |
A 7-day free trial for new subscribers |
In Play Console, go to Monetize → Products → Subscriptions → Create subscription.
-
Choose the product ID carefully, because you can't change or reuse it later. We used a single subscription for all our plans.
-
Add a base plan. Pick Auto-renewing, set the billing period (for example, Monthly) and set the prices. Play suggests prices for every country based on the one you enter. Save it, then Activate the base plan.
-
Add the free trial offer. On that base plan, click Add offer and set:
- Eligibility: choose New customer acquisition, then Never had this subscription. This stops people from starting a new free trial every time they cancel.
- Phases: add one phase of type Free trial and set its length, for example 7 days.
Save the offer, then Activate it.
-
Repeat for each billing period. We made a yearly base plan too, with its own free trial offer. Each base plan needs its own offer, because an offer on the monthly plan doesn't apply to the yearly one.
You don't need to pick the trial in code. When the app buys a base plan, the RevenueCat SDK chooses the best offer the user is eligible for, so a new user gets the trial and a returning user pays the normal price.
Keep in mind that nothing goes live until it's activated. A base plan or offer that's still a draft is one of the most common reasons for an empty paywall.
RevenueCat needs permission to ask Google Play about your app's purchases. You give it that permission with a service account, which is a Google account meant for a program instead of a person. It signs in with a JSON key file that you download.
- Open Google Cloud Console and create a project, or pick an existing one.
- Go to APIs & Services → Library and enable these APIs:
- Google Play Android Developer API
- Google Play Developer Reporting API
- Cloud Pub/Sub API, which you'll use in Step 4
- Go to IAM & Admin → Service Accounts → Create service account, and give it a name like
revenuecat-service-account.
- Give it the Pub/Sub Admin role, so RevenueCat can set up notifications in Step 4, and the Monitoring Viewer role.
- Open the service account and go to Keys → Add key → Create new key → JSON. A
.json file downloads.
Treat that file like a password, because anyone who has it can act as the service account. Never commit it to your repository.
- In Play Console, go to Users and permissions → Invite new users and paste the service account's email address. It looks like
revenuecat-service-account@your-project.iam.gserviceaccount.com.
- Under App permissions, add your app and turn on:
- View app information and download bulk reports (read-only)
- View financial data, orders and cancellation survey responses
- Manage orders and subscriptions
- Click Invite user. A service account doesn't need to accept the invite.
Play Console no longer needs to be linked to the Google Cloud project, so you can skip the API access page.
In your RevenueCat project, add a Play Store app with your package name, and upload the JSON file under Service Account Credentials.
RevenueCat will probably say the credentials are invalid at first, because Google can take up to 36 hours to activate a new service account. A tip that's widely shared in the RevenueCat community is to edit and save any subscription in Play Console (changing its description is enough), which seems to speed this up.
When we clicked Create new key, Google Cloud showed the error "Service account key creation is disabled". Our organization had the iam.disableServiceAccountKeyCreation policy turned on, which Google enables automatically for many newer organizations as part of its "secure by default" settings.
The error message suggests more secure alternatives to keys, such as Workload Identity Federation. Those only work for code you run yourself, though. RevenueCat is a third-party service, and a JSON key file is the only credential it accepts.
That left us with two options:
- Turn the policy off for this one project. Someone with the Organization Policy Administrator role goes to IAM & Admin → Organization Policies, opens Disable service account key creation, chooses Override parent's policy and sets enforcement to Off. Once the key is created, they set the policy back to Inherit parent's policy. Keys that already exist keep working. Newer organizations may also have a second version of this policy,
iam.managed.disableServiceAccountKeyCreation, which needs the same change.
- Create the service account in a project outside the organization. A Google Cloud project created from a personal Google account doesn't belong to an organization, so the policy doesn't apply. The service account can live in any project, because Play Console only cares about its email address.
We didn't have the organization admin role, so we went with option 2. If you do the same, add a second person as an Owner of that Cloud project, so you don't lose access if something happens to the personal account. If you can get the policy changed for one project, though, option 1 is the better choice, because it keeps everything under your organization's security settings.
Real-time developer notifications let Google Play tell RevenueCat as soon as something changes: a renewal, a cancellation, a failed payment, or a trial turning into a paid subscription. Without them, RevenueCat only finds out the next time the app checks in, so a user who cancelled could keep access for longer than they should.
Google sends these notifications through Pub/Sub, Google Cloud's messaging service. RevenueCat creates the Pub/Sub topic for you, which is why the service account needed the Pub/Sub Admin role in Step 3.
- In RevenueCat, open your Play Store app's settings and find Google developer notifications. Connect it and choose your Cloud project. RevenueCat creates a topic and shows its name, which looks like
projects/your-project/topics/....
- Copy the topic name.
- In Play Console, go to Monetize → Monetization setup, find Real-time developer notifications, paste the topic name and save.
- Click Send test notification, then check in RevenueCat that it arrived.
If the Cloud project asks you to add a billing account before you can enable Pub/Sub, add one. The number of messages a single app sends stays within Google's free tier.
This step tells RevenueCat which Google Play products exist, what they unlock, and which ones your paywall should show.
- Import the products. In RevenueCat, go to Products, choose your Play Store app and import. Each base plan shows up as its own product named
subscriptionId:basePlanId, for example pro:monthly and pro:yearly.
- Attach them to the entitlement. Go to Entitlements, open your entitlement (we called ours
pro), and attach both Play products. If you skip this, a purchase goes through and the user is charged, but the app doesn't unlock, because nothing links the product to access.
- Add them to the offering. Go to Offerings and open the offering your app loads. Each package (
$rc_monthly and $rc_annual) has a row for each store, so pick the matching Play product in the Play Store row.
- Mark the offering as Current. The app asks RevenueCat for the current offering, so this decides what the paywall shows. You can switch to a different offering later without releasing a new version.
If you already sell on iOS, use the same entitlement and the same offering. Put each Android product in the same package as its iOS equivalent, so the monthly package is monthly on both stores.
When you pick a Play product in the offering, RevenueCat shows a "not backwards compatible" warning. It says the product is only supported by version 6 or later of its Android SDK, and offers a fallback product field. That's because products built from base plans didn't exist before Google's 2022 subscription changes, so very old SDK versions can't buy them. Any recent purchases_flutter release is well past that point, so you can leave the fallback empty. You only need it if old versions of your app, built with an old SDK, are still in use and need to be able to buy.
Each package also has a Test Store row. RevenueCat's Test Store lets debug builds go through the purchase flow without a real store. If you plan to use it (more on that in Step 6), create Test Store products and pick them here too. Otherwise, those packages will be empty in debug builds.
The app code is the same for Android and iOS, and it does five things: picks the right API key, starts the SDK, tells RevenueCat who the user is, decides whether to show the paywall, and lets users restore their purchases.
RevenueCat gives each store its own public API key. Android keys start with goog_, and iOS keys start with appl_. These keys are safe to ship inside the app, but we still keep them in .env files (loaded with flutter_dotenv) so we can use different values for development and production:
REVENUECAT_API_KEY_TEST=test_...
REVENUECAT_API_KEY_IOS=appl_...
REVENUECAT_API_KEY_ANDROID=goog_...
A config class picks the key based on the platform and the build type. Debug builds use RevenueCat's Test Store key by default, so developers can try the purchase flow without a store account. Release builds never use it, because the SDK crashes on a test key in a release build.
class SubscriptionConfig {
static const entitlementId = 'pro';
static const offeringId = 'pro'; // fallback if no offering is marked Current
static const enforced = bool.fromEnvironment(
'SUBSCRIPTIONS_ENFORCED',
defaultValue: true,
);
static const useTestStore =
kDebugMode && !bool.fromEnvironment('DISABLE_TEST_STORE');
static String get apiKey {
if (useTestStore) return dotenv.env['REVENUECAT_API_KEY_TEST'] ?? '';
return Platform.isIOS
? dotenv.env['REVENUECAT_API_KEY_IOS'] ?? ''
: dotenv.env['REVENUECAT_API_KEY_ANDROID'] ?? '';
}
static bool get hasUsableKey => isUsableKey(apiKey, useTestStore);
static bool isUsableKey(String key, bool testStore) {
if (testStore) return key.isNotEmpty;
return key.startsWith('appl_') || key.startsWith('goog_');
}
}
If the paywall is turned on but the app has no valid key, it can never load any plans, and every user would be stuck on an empty paywall. We decided a crash at startup is better than shipping that, because a crash gets noticed in testing. That's why our first Android build in Step 1 crashed.
Future<void> configure() async {
if (!SubscriptionConfig.hasUsableKey) {
if (SubscriptionConfig.enforced) {
throw StateError('Subscriptions are on but no usable RevenueCat key was found.');
}
return; // paywall switched off for this build
}
await Purchases.setLogLevel(kDebugMode ? LogLevel.debug : LogLevel.warn);
await Purchases.configure(PurchasesConfiguration(SubscriptionConfig.apiKey));
Purchases.addCustomerInfoUpdateListener(_onCustomerInfo);
}
We also have a unit test that fails if .env.prod is missing a real goog_ or appl_ key, so the test run catches the problem before a release build does. Once the Android key exists, run it with --dart-define=RELEASE_PLATFORM=android.
If you need to ship a build with the paywall turned off, pass --dart-define=SUBSCRIPTIONS_ENFORCED=false.
By default, RevenueCat gives each install an anonymous ID. Call logIn with your own user ID after the user signs in, so their subscription follows them across devices and reinstalls, and call logOut when they sign out:
final result = await Purchases.logIn(userId);
_onCustomerInfo(result.customerInfo);
Load the current offering and pass it to the paywall. We use PaywallView from purchases_ui_flutter, which draws a paywall you design in RevenueCat's dashboard and shows the trial and price for each plan automatically:
final offerings = await Purchases.getOfferings();
final offering = offerings.current ?? offerings.getOffering(SubscriptionConfig.offeringId);
The app checks the entitlement, never a product ID. Our gate function only sends a user to the paywall when we know they don't have access:
if (entitlement.grantsAccess) return home;
// Can't reach RevenueCat or our server right now? Let the user in, but only
// for a short time after the last successful check.
if (!entitlement.isKnown &&
now.difference(entitlement.verifiedAt) < graceWindow) {
return home;
}
return GateDecision.paywall;
The grace window, which is 72 hours for us, means a paying user on a plane or a bad connection doesn't get locked out. A subscription we know has expired never gets the grace window.
Give users a Restore Purchases button on the paywall. It asks the store for any subscription tied to the user's Google account, which helps someone who reinstalled the app or changed phones:
final info = await Purchases.restorePurchases();
final active = info.entitlements.all[SubscriptionConfig.entitlementId]?.isActive ?? false;
Show a clear message either way. Without one, a restore that finds nothing looks exactly like a button that does nothing.
Google Play has license testers, which are Google accounts that can buy your subscriptions without being charged. Their subscriptions also renew much faster than real time, so you can watch a whole trial end and renew in a few minutes instead of a week.
License testing is a setting for your whole developer account, so you won't find it in your app's menus.
- In Play Console, go back to the account home page by clicking All apps or the Play Console logo.
- Click Settings in the left sidebar, then License testing.
- Add your testers' Gmail addresses, or create an email list and tick it.
- Set License response to RESPOND_NORMALLY and save.
If you can't see Settings or License testing, your Play Console user doesn't have admin access, so ask the account owner.
Testers also need to be on the Internal testing list from Step 1 and to have opened the opt-in link. Being a license tester only means they don't get charged.
The first option is to install from the internal testing link. Upload a new build that includes the real goog_ key, then install it from the opt-in link on a phone signed in to a license tester's account. This is the closest to what real users get.
The second option is to run a debug build from your computer, which is faster while you're changing code. Our debug builds use RevenueCat's Test Store by default, so to hit real Google Play billing, we turn that off:
flutter run --dart-define=DISABLE_TEST_STORE=true
For this to work, the phone's Play Store account has to be a license tester, and the app's package name has to match the one in Play Console.
The first time we ran a debug build on a phone that already had the app installed from Play, the install failed:
INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.example.app
signatures do not match newer version
The version from Play is signed with Google's app signing key, while a debug build is signed with your computer's debug key, and Android won't replace an app with one signed by a different key. To fix it, uninstall the Play version first. Note that this deletes the app's data on that phone:
adb uninstall com.example.app
flutter run --dart-define=DISABLE_TEST_STORE=true
The same thing happens in reverse. To go back to the Play version, uninstall the debug build first.
For license testers, a free trial lasts a few minutes and each renewal comes a few minutes after the last, so you can watch the whole lifecycle in well under an hour.
The paywall should show both plans with the free trial, and buying a plan should unlock the app straight away. In RevenueCat's dashboard, the customer shows up with a trial status, and a few minutes later you'll see the trial convert to a paid subscription and then renew. If you cancel in the Play Store app, RevenueCat should pick it up, and the user should lose access once the current period ends. Finally, Restore Purchases should bring the subscription back after you reinstall the app.
If the paywall is empty, check these in order: the offering is marked Current, the products are in the offering, the base plans and offers are active in Play Console, and RevenueCat shows the service account credentials as valid.
Google Play requires your paywall to state how long the free trial lasts, what the user pays once it ends, and that the subscription renews until they cancel. RevenueCat's paywall templates show the trial and price for each plan, so check that the renewal wording is there too, along with working links to your terms of use and privacy policy.
To release, build the bundle with flutter build appbundle --release, raise the build number above anything you've already uploaded, and upload it to the internal testing track. Have a license tester buy a plan on that exact build, since it's the first one running with your production .env file and the real goog_ key, and only promote it to production once that purchase works.
If we were starting over, these are the things we'd want to know on day one:
- Upload a build first. You can't create a subscription without one, and it doesn't even need to work.
- Ask about the organization policy early. If your company uses Google Workspace, check whether service account keys are blocked before you start, because getting the policy changed can take days.
- Create the service account early. Google can take up to 36 hours to activate it, so set it up before you need it.
- Check the entitlement, not the product. That keeps the app code the same when your plans change.
- Make a missing key impossible to ship. A startup check plus a test that reads the production
.env file saved us from a release where nobody could subscribe.
- Use license testers for everything. Fast renewals turn a week of waiting into a few minutes.