Appstore SDK Compatible With Google Play Billing
If you have an existing Android app that is integrated with the Google Play Billing Library, you can use the Appstore SDK Compatible With Google Play Billing API to port your app to the Amazon Appstore with minimal changes. The Appstore SDK Compatible With Google Play Billing API supports consumable and entitlement in-app purchases (IAP). Subscriptions IAPs are not supported.
The following table shows a feature comparison between the Google Play Billing Library, Amazon Appstore SDK v3.0.3, and Amazon Appstore SDK Compatible With Google Play Billing API v4.0.0.
Feature | Google Play Billing Library | Appstore SDK v3.0.3 | Appstore SDK Compatible With Google Play Billing API v4.0.0 |
---|---|---|---|
Subscriptions | See note | ||
Entitlements | |||
Consumables | |||
Digital Rights Management (DRM) |
Download the Appstore SDK
To download the Appstore SDK Compatible With Google Play Billing API, visit SDK Downloads. The download includes the Appstore SDK JAR file and API documentation.
Integrate the Appstore SDK
Use this step-by-step guide to integrate the Appstore SDK Compatible With Google Play Billing API with your app.
Step 1. Add the Appstore SDK to your app
Manually add the Appstore SDK to your Android app project:
- Expand your app folder and select libs (If you don't have a libs folder, create one). Paste the appstore-sdk-compat-beta-4.0.0.jar file into this directory.
- Open your app folder's build.gradle file and add a dependency on the appstore-sdk-compat-beta-4.0.0.jar.
For example:
dependencies { implementation files('libs/appstore-sdk-compat-beta-4.0.0.jar') }
- Sync your project by selecting Sync Now at the top of your build.gradle file in your IDE.
Optionally, you can remove the Google Play Billing Library dependency from your app.
Step 2. Configure your Android app with the public key
This public key, which is unique per app, establishes a secure communication channel between the Amazon Appstore and your app. When you generate the public key from the Amazon Developer Console, Amazon generates a corresponding private key. These public and private keys form a key pair to sign license responses. Through this key pairing, you ensure that the users who install your app are authorized.
To configure your Android app with the public key:
- Log in to the Developer Console with your developer account.
- Go to Apps & Services > My Apps. If you have an existing app, click on the app. Otherwise, create a new app by clicking on the Add New App button and selecting Android, then complete the New App Submission page.
- Go to the Add App Bundles or APK Files section on the App Information tab.
- Click Public Key.
- In the Public Key dialog box that appears, click the AppstoreAuthenticationKey.pem link to download a PEM file. This file contains your public key.
- Copy the AppstoreAuthenticationKey.pem file. Then paste it into the app/src/main/assets folder of your Android app project. If you don't have this folder, create one.
Optionally, you can remove the Google Play Billing public key dependency.
Step 3. Configure your AndroidManifest.xml file with receiver
The Appstore SDK performs all of its activities in an asynchronous manner. Your app needs to receive broadcast intents from the Amazon Appstore through the BillingResponseReceiver
class. This class is never used directly in your app, but for your app to receive intents, you must add an entry for the BillingResponseReceiver
to your manifest.
The following example code shows how to add a BillingResponseReceiver
to the AndroidManifest.xml file for the Appstore SDK. If your app targets Android 12 or higher, you must explicitly set android:exported
to true
in the MainActivity
and ResponseReceiver
.
<application>
...
<activity android:name="com.amazon.sample.iap.entitlement.MainActivity"
android:label="@string/app_name" android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.amazon.device.iap.billingclient.api.BillingResponseReceiver" android:exported="true"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY">
<intent-filter>
<action android:name="com.amazon.inapp.purchasing.NOTIFY" />
</intent-filter>
</receiver>
...
</application>
Step 4. Update import statements
Update Google Play Billing imports in your app's codebase to use Appstore SDK imports by finding all usages of the com.android.billingclient.api
prefix and replacing them with the com.amazon.device.iap.billingclient.api
prefix.
If any Appstore SDK import statement is unresolved, that indicates it isn't supported by the Appstore SDK. Remove or modify its usage in the app to make it work with the Amazon Appstore.
Next steps
See Implement the Google Play Billing Interface.
Last updated: Nov 17, 2022