目录

1. Configuring AppGallery Connect

Before app development, configure the app information in AppGallery Connect.  

1.1 Registering as a Developer  

Before developing an app, you will need to register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Account Registration and Verification.  

1.2 Creating an App  

Create an app by referring to Creating a Project and Creating an App in the Project. Special configurations for a game app are as follows:

Note:
AppGalleryKit game must end with .huawei or .HUAWEI. Otherwise, the app will be rejected.        

1.3 Generating a Signing Certificate Fingerprint  

A signing certificate fingerprint is used to verify the authenticity of an app, when the app attempts to access the HMS Core(APK) through HMS SDK. Before using HMS SDK, you must locally generate the signing certificate fingerprint, and configure it in AppGallery Connect.      

Perform the following steps:      

1. Open the command line tool (using the CMD command) and run the cd command to enter the directory where keytool.exe is located. In the following example, the Java program is installed in Program Files (x86) of drive C.      

 

2. Run keytool -list -v -keystore <keystore-file> and follow the instructions.
In the preceding command, <keystore-file> is the complete path to the app's signature file.
Example:

  1. C:\Program Files (x86)\Java\jdk1.7.0_25\bin>keytool -list -v -keystore E:\HMS_SDK_3.0.0.301\Sample\HMSSdkSample_3.0.0.301_AS\HmsSample\android.keystore

3. Obtain the SHA256 fingerprint from the result.   

1.4 Configuring the Signing Certificate Fingerprint  

1. Sign in to AppGallery Connect and select My projects.      

2. Find your project from the project list and click the app on the project card.

3. On the Project Setting page, set SHA-256 certificate fingerprint to the SHA-256 fingerprint from Generating a Signing Certificate Fingerprint.      

      

4. After completing configuration, click .      

1.5 Enabling Required Services  

For details, please refer to Enabling Services. If you enable the HUAWEI IAP service for the first time, you need to sign a payment agreement. For details, see Configuring IAP Service Parameters.  

If you have enabled HUAWEI Analytics Kit for joint operation, enable HUAWEI Advanced Analytics Service,For details, see Enabling the HUAWEI Advanced Analytics Service.  

1.6 Configuring Achievements  

Achievements are a great way to increase player engagement within your game, and to give the player more incentive to continue playing the game. If your app implements an achievement system, configure achievements in AppGallery Connect in advance.      

1.7 Configuring Events

The events feature allows you to collect specific data generated by your players during gameplay and store them on the Huawei game server for AppGallery Connect to use as feedback to conduct game analytics. If your app implements an event system, configure events in AppGallery Connect in advance.

1.8 Configuring the Subscription Callback Address

When key events about a subscription occur (e.g. successful initial subscription, successful renewal, and cancellation of subscription), Huawei payment server will send notifications to the developer server if a subscription callback address has been configured in advance. For details about how to configure the callback address, please refer to Configuring IAP Service Parameters.  

1.9 Configuring In-App Product Information

If your app will be released globally, it is recommended that you configure in-app product information in AppGallery Connect in advance, so that the corresponding in-app product ID can be directly transferred to the payment interface during an interface call, without requiring you to personally manage product pricing.    

During app development and testing, you can test product payments with a tester account in the sandbox environment. During the testing period, when a purchase is initiated by the tester account, the Huawei payment server will identify the tester account and directly process a successful payment, without going through the payment process. For details, please refer to Sandbox Testing.   

1.10 Configuring Product Marketing

A developer can package a specified product for marketing and display the product publicity image, product name, and product description on their app details page in AppGallery (10.2.0 and later versions). For details, see Product Marketing Management.

2. Integrating HMS SDK

2.1 Integrating the HMS SDK into Your App Project in the Android Studio IDE

For AndroidStudio, Huawei provides an HMS SDK that can be integrated by using the Maven repository. Before app development, you will need to integrate HMS SDK into your AndroidStudio.

1. Add the AppGallery Connect configuration file of the current app to your AndroidStudio.

    a. Sign in to AppGallery Connect and select My projects.

    b. Find your project from the project list and click the app on the project card.  

    c. On the Project Setting page, click agconnect-services.json to download the configuration file.

    d. Copy the agconnect-services.json file to the app root directory.  

       

2. Configure the Maven repository address for HMS SDK and the AppGallery Connect plug-in address.  

     a. Open the build.gradle file in the root directory of your AndroidStudio project.  

      

     b. Go to allprojects -> repositories and configure the Maven repository address for HMS SDK.

  1. allprojects {
  2.            repositories {
  3.                google()
  4.                jcenter()
  5.                maven {url 'https://developer.huawei.com/repo/'}
  6.            }
  7.        }
Note:
The Maven repository address cannot be visited from a browser. It can only be configured in the IDE.        

    c. Go to buildscript->repositories and configure the Maven repository address for HMS SDK. 

  1. buildscript {
  2.            repositories {
  3.                google()
  4.                jcenter()
  5.                maven {url 'https://developer.huawei.com/repo/'}
  6.            }
  7. } 

     d. Go to buildscript->dependencies and configure the AppGallery Connect plug-in address.  

  1. buildscript {
  2.            dependencies {
  3.             classpath 'com.huawei.agconnect:agcp:1.3.2.301'
  4.            }
  5. }

3. Add compile dependencies.  

    a. Open the build.gradle file in the app directory.  

      

     b. Add the AppGallery Connect plug-in dependency to the bottom of the file.  

  1. apply plugin: 'com.huawei.agconnect'

     c. Configure compile dependencies.  

  1. dependencies {      
  2.    implementation 'com.huawei.hms:hwid:{version}'      
  3.    implementation 'com.huawei.hms:iap:{version}'  
  4.    implementation 'com.huawei.hms:game:{version}'  
  5.    implementation 'com.huawei.hms:hianalytics:{version}'  
  6. }

Note:

4. Re-open the modified build.gradle file. You will find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization has completed.  

 

Note:

If an error occurs, check the network connection and the configurations in the gradle file.        

5. Configure multi-language information.  

Open the build.gradle file in the app directory of your project.

 

Go to android -> defaultConfig and add the resConfigs configuration. en (English) and zh-rCN (Simplified Chinese) are mandatory languages. The format is as displayed below:  

  1. android {
  2.        defaultConfig {
  3.                ...
  4.                resConfigs "en", "zh-rCN", "Other languages to be supported."
  5.        }
  6. }

For details about the languages supported by HMS SDK, please refer to Languages Supported by HMS SDK.  

2.2 Integrating the HMS SDK into Your App Project in the Eclipse IDE

Before starting your development in the Eclipse Integrated Development Environment (IDE), download the HMS SDK and integrate it into your app project.

2.2.1 Downloading the SDK

1. Download and decompress the zip packages of the HMS Base SDK , HUAWEI Account SDK, HUAWEI IAP SDK and HUAWEI Game Service SDK. 

For details, please refer to Eclipse SDK Download.

For details about how to integrate the Huawei Analytics service, see Integrating the Analytics Service SDK in the Eclipse Project.

2. Import all SDK projects to your workspace.

    a. Go to File > Import > Android > Existing Android Code Into Workspace and click Next.

    b. Click Browse and navigate to the directory where your projects are located. Select the projects to be imported under Projects and click Finish. By default, all projects are selected. You can change as needed.

NOTE: The projects to be imported must be located in the same drive as the workspace, for example, D:\. If they are not in the same drive, select Copy projects into workspace to copy the project file to the workspace.

2.2.2 Adding Project Dependencies

1. Right-click your app project and choose Properties from the shortcut menu.

2. Choose Resource > Android from the navigation tree, click Add, select the imported projects, and click Apply and Close.

3. Right-click the HMSSdkAvailableUpdate project and choose Properties from the shortcut menu.

4. Choose Android from the navigation tree. Then, click Add in the Library area, select the HMSSdkUI project, and click Apply and Close.

5. As the XML file in the Eclipse IDE does not support the dollar sign ($), replace ${applicationId} in the AndroidManifest.xml file of the HMSSdkAvaliableUpdate and Agconnect-core projects with your app package name.

  1. <application>
  2.    <provider
  3.        android:name="com.huawei.agconnect.core.provider.AGConnectInitializeProvider"
  4.        android:authorities="${applicationId}.AGCInitializeProvider"
  5.        android:exported="false" />
  6.    <service
  7.        android:name="com.huawei.agconnect.core.ServiceDiscovery"
  8.        android:exported="false" />
  9. </application>

2.2.3 Copying the HMSSdkStats Properties Files to Your App Project Directory

Copy the properties files in the assets directory of the HMSSdkStats project to the assets directory of your app project.

NOTE: If any other kits are involved, copy the properties files of these kits to your app project directory.

2.2.4 Configuring the project.properties File

Find and open the file in your project directory and add the following code to merge the manifest files in the subprojects:

  1. manifestmerger.enabled=true
Note:
The ADT version must be 17 or later.

2.2.5 Adding the AppGallery Connect Configuration File

1. Sign in to AppGallery Connect and select My projects.

2. Find your project from the project list and click the app on the project card.

3. On the Project Setting page, click agconnect-services.json to download the configuration file.

4. The Eclipse IDE does not support the AppGallery Connect plug-in. Therefore, you need to place the agconnect-services.json file in the assets directory of your project and add the following code to the Application subclass of the project. If the project does not have an Application subclass, you need to create a subclass that is inherited from the Application subclass. For example, create a MyApplication class.

  1. public class MyApplication extends Application{
  2.    @Override
  3.    public void onCreate() {
  4.        super.onCreate();
  5.    }
  6.    // TODO: Add the following code:
  7.    @Override
  8.    protected void attachBaseContext(Context context) {
  9.        super.attachBaseContext(context);
  10.        AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
  11.        config.overlayWith(new LazyInputStream(context) {
  12.            public InputStream get(Context context) {
  13.                try {
  14.                    return context.getAssets().open("agconnect-services.json");
  15.                } catch (IOException e) {
  16.                    return null;
  17.                }
  18.            }
  19.        });
  20.    }
  21.    // TODO: End
  22. }

You still need to import the following classes:

  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import com.huawei.agconnect.config.AGConnectServicesConfig;
  4. import com.huawei.agconnect.config.LazyInputStream;
  5. import android.app.Application;
  6. import android.content.Context;
  7. import android.util.Log;

6. Open the AndroidManifest.xml file of your project and add the Application subclass name to the application section. If the subclass name has been added, skip this step. In the following example, add the MyApplication class name.

  1. <application
  2.    android:name=".MyApplication"
  3.    ...
  4.    >
  5. ...

7. In the Eclipse IDE menu bar, click Project, then Clean.

3. Configuring Obfuscation Scripts

Do not obfuscate HMS SDK before compiling the APK. Otherwise, function errors may occur.

1. Open the obfuscation configuration file of your project.  

2. Add configuration to ensure that HMS SDK is not obfuscated.  

  1. -ignorewarnings
  2. -keepattributes *Annotation*
  3. -keepattributes Exceptions
  4. -keepattributes InnerClasses
  5. -keepattributes Signature
  6. -keepattributes SourceFile,LineNumberTable
  7. -keep class com.hianalytics.android.**{*;}
  8. -keep class com.huawei.updatesdk.**{*;}
  9. -keep class com.huawei.hms.**{*;}
  10. -keep class com.huawei.gamebox.plugin.gameservice.**{*;}
  11. -keep interface com.huawei.hms.analytics.type.HAEventType{*;}
  12. -keep interface com.huawei.hms.analytics.type.HAParamType{*;}
  13. -keep class com.huawei.hms.analytics.HiAnalyticsInstance{*;}
  14. -keep class com.huawei.hms.analytics.HiAnalytics{*;}

3. If you have used AndResGuard, add the AndResGuard allowlist to the obfuscation configuration file.

  1. "R.string.agc*",
  2. "R.string.hms*",
  3. "R.string.connect_server_fail_prompt_toast",
  4. "R.string.getting_message_fail_prompt_toast",    
  5. "R.string.no_available_network_prompt_toast",    
  6. "R.string.third_app_*",    
  7. "R.layout.hms*",      
  8. "R.drawable.upsdk*",    
  9. "R.color.upsdk*",  
  10. "R.dimen.upsdk*",  
  11. "R.style.upsdk*",
  12. "R.id.scroll_layout",
  13. "R.id.divider",
  14. "R.id.name_textview",
  15. "R.id.version_textview",
  16. "R.id.appsize_textview",
  17. "R.id.allsize_textview",
  18. "R.id.content_textview",
  19. "R.id.third_app_dl_progress_text",
  20. "R.id.cancel_bg",
  21. "R.id.third_app_dl_progressbar",
  22. "R.id.upsdk*",
  23. "R.string.upsdk*",
  24. "R.layout.upsdk*"