Skip to main content


If you haven't created your apps at Google Play Console and Huawei App Gallery Console yet, please start by following this guide step-by-step.

The first step to integrate with Appmate SDK is to add the library to your app and initialize an instance of the PurchaseClient. With Appmate SDK, you will be able to manage all the processes of Google's and Huawei's IAP apis through the single sdk. To integrate the Appmate, you need to do some additionsto both root-level and app-level build.gradle files.

Before start the implementation you need to make sure you've been added agconnect-services.json file under “app” folder of our project in order to access In-App Purchase services.

First in Android Studio root-level(project-level) build.gradle file, add rules to include the SDK Maven Repository, HUAWEI Maven repository and HUAWEI agcp plugin.

buildscript {    repositories {        // ...
        maven { url '' }        maven {            url ''            allowInsecureProtocol true        }    }    dependencies {        // ...
        classpath "com.huawei.agconnect:agcp:"    }}
allprojects {    repositories {        // ...
        maven { url '' }        maven {            url ''            allowInsecureProtocol true        }    }}

Then in your module(app-level) build.gradle file, add the following lines for HUAWEI agcp plugin and SDK dependency.

apply plugin: ''// Add the following lineapply plugin: 'com.huawei.agconnect'  // HUAWEI agconnect Gradle plugin
android {    // ...          compileOptions {      sourceCompatibility JavaVersion.VERSION_1_8      targetCompatibility JavaVersion.VERSION_1_8    }}
dependencies {    // ...        implementation 'com.huawei.appmate:iap:1.1.14'}

Configure Proguard#

Also you should add some rules to the obfuscation configuration file of your project.

-keep class com.huawei.appmate.**{*;}
-ignorewarnings-keepattributes *Annotation*-keepattributes Exceptions-keepattributes InnerClasses-keepattributes Signature-keepattributes SourceFile, LineNumberTable
-keep class com.huawei.hianalytics.**{*;}-keep class com.huawei.updatesdk.**{*;}-keep class com.huawei.hms.**{*;}


Minimum API Level: 19+

Initialization of PurchaseClient#

Once you've added a dependency on the appmate SDK, you need to initialize a PurchaseClient instance with ApiKey and UserId(optional) configurations. It's a singleton class that you can create it once in your app and call by PurchaseClient instance throughout your app. We recommend you to create it in the Application class of your app or within a singleton class. PurchaseClient is the main class for communication between the appmate SDK and the rest of your app.

public class MyApplication extends Application {    @Override    public void onCreate() {        super.onCreate();        PurchaseClient.getInstance(this, apiKey);    }}

Remember to also declare your Application class in the AndroidManifest.xml file.

  <manifest    ...    >    <uses-permission android:name="android.permission.INTERNET" />    <application      ...      android:label="@string/app_name"      android:name=".MyApplication"      >      ...    </application>    ...  </manifest>

PurchaseClient.getInstance method takes three parameters as below:

  • Application: It's mandatory when creating an instance of PurchaseClient.
  • ApiKey: It's also mandatory when creating an instance. Api Key can be found in your app settings page in the appmate Web Console.
  • UserId: It's an optional parameter that uniquely identifies your users within your application. You should set it only if you have a membership system for your app. You don't have to add it to PurchaseClient's constructor when creating an instance. Alternatively, you could specify your own user identifiers with PurchaseClient.instance.setUserId() later in your app lifecycle. This method requires a userId as a type of String and should be a unique value. It's necessary to fetch products and make purchase.


Also you can retrieve userId from appmate SDK regardless of you set a userId or a random userId is created.

PurchaseClient.getInstance().getUserId(new ReceivedDataListener<String, GenericError>() {    @Override    public void onSucceeded(String userId) {    }
    @Override    public void onError(GenericError error) {    }});

By default appmate SDK determines platform type depending on which environment is supported. Huawei devices supports Huawei Mobile Services (HMS) and other Android devices supports Google Mobile Services (GMS). Some Huawei devices supports both of HMS and GMS. In this situation appmate SDK works over GMS. But developers can set running platform type by calling setPlatformType method. If the device is not supporting the passed platform type, onError will be triggered.

PurchaseClient.getInstance().setPlatformType(PlatformServiceType.HMS, new ReceivedDataListener<Boolean, GenericError>() {    @Override    public void onSucceeded(Boolean data) {     }
    @Override    public void onError(GenericError error) {    }});

Now that you have appmate sdk installed, you can continue with creating products in the next step. The appmate Web Console provides a web interface that you can use to manage your products.

To create and configure products, see Creating Products page.