Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.
This section introduces preparations for accessing HUAWEI Push Kit.
The preparations are as follows:
1. Configure app information in AppGallery Connect.
2. Integrate the HMS SDK.
3. Configure the manifest file.
4. Configure obfuscation scripts.
Before you start developing an app, configure app information in AppGallery Connect.
Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Create an app by referring to Creating a Project and Creating an App in the Project. Set the following parameters as described:
Platform: Select Android
Device: Select Mobile phone
App category: Select App or Game
A signing certificate fingerprint is used to verify the authenticity of an app when the app attempts to access HMS Core (APK) through the HMS SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect.
Please ensure that the following conditions are met:
You have created the app's signature file. For details, please refer to Generating a Signing Certificate.
The JDK has been installed on your PC.
Perform the following steps:
1. Open the command line tool (using the cmd command) and run the cd command to go to the directory where keytool.exe is located. In the following example, the Java program is installed in Program Files (x86) in the C drive.

2. Run keytool -list -v -keystore <keystore-file> and respond as prompted.
In the preceding command, <keystore-file> is the complete path to the app's signature file.
Example:
- >keytool -list -v -keystore E:\HmsSample\android.keystore
3. Obtain the SHA-256 fingerprint from the result.

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
. The configuration takes effect in about 15 minutes.
To use HUAWEI Push Kit, you must set the data storage location. For details, please refer to Setting Data Storage Location.
If the data storage location is not set, the following functions will be unavailable: topic-based messaging, messaging through the WebPush agent, and messaging to iOS apps. If the data storage location is different from your server location, or is different from the location of a user that the app serves, messaging delay will increase. To reduce the delay caused by messaging across regions around the world, you are advised to set the data storage location based on the location of a user that the app serves. For example, if you are a developer in Latin America and most of your app users are in Latin America, you are advised to set your data storage location to Singapore. If you are a developer in the Chinese Mainland but most of your app users are in Europe, you are advised to set your data storage location to Germany.
Enable HUAWEI Push Kit.
For details, please refer to Enabling Services.
Set HUAWEI Push Kit parameters.
For details, please refer to Configuring Push Service Parameters.
If you are using Android Studio, you can integrate your HMS Core SDK by using the Maven repository. Before you start developing an app, integrate the HMS Core SDK into your Android Studio first.
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.
e. Copy the agconnect-services.json file to the app's root directory.

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 the HMS Core SDK.
- allprojects {
- repositories {
- google()
- jcenter()
- maven {url 'https://developer.huawei.com/repo/'}
- }
- }
c. Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
- buildscript {
- repositories {
- google()
- jcenter()
- maven {url 'https://developer.huawei.com/repo/'}
- }
- }
d. Go to buildscript > dependencies and add dependency configurations.
- buildscript {
- dependencies {
- classpath 'com.huawei.agconnect:agcp:1.3.1.300'
- }
- }
a. Open the build.gradle file in the app directory.

b. Configure build dependencies.
- dependencies {
- // Retain other existing dependencies.
- implementation 'com.huawei.hms:push:{version}'
- }
c. Add the authentication configuration to the file header.
- apply plugin: 'com.huawei.agconnect'
Copy the signature file generated in Generating a Signing Certificate Fingerprint to the app directory of your project and configure the signature in the build.gradle file.
- android {
- signingConfigs {
- config {
- keyAlias 'xxx'
- keyPassword '123456'
- storeFile file('xxx.jks')
- storePassword '123456'
- }
- }
- buildTypes {
- debug {
- signingConfig signingConfigs.config
- }
- release {
- signingConfig signingConfigs.config
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
- }
- }
- }
Open the modified build.gradle file again. You will find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization is complete.

● By default, your app supports all languages provided by the HMS Core SDK. If your app uses all these languages, skip the operation procedure in this section.
● If your app uses only some of these languages, follow the operation procedure in this section to complete the required configuration.
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. For example, if your app supports only English and Simplified Chinese, the configuration is as follows:
- android {
- defaultConfig {
- ...
- resConfigs "en", "zh-rCN"
- }
- }
For details about the languages supported by the HMS SDK, please refer to Languages Supported by HMS SDK.
If you are using Eclipse, you can download the HMS Core SDK and integrate it into your Eclipse project.
1. Download and decompress the ZIP packages of the HMS Base SDK and SDKs of the required kits. For details, please refer to Eclipse SDK Download.
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.

1. Right-click your app project and choose Properties from the shortcut menu.
2. Choose Android from the navigation tree. Then click Add in the Library area, 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. Because 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.
- <application>
- <provider
- android:name="com.huawei.agconnect.core.provider.AGConnectInitializeProvider"
- android:authorities="${applicationId}.AGCInitializeProvider"
- android:exported="false" />
- <service
- android:name="com.huawei.agconnect.core.ServiceDiscovery"
- android:exported="false" />
- </application>
Copy the resource files in the assets directory of the HMSSdkStats project to the assets directory of your project.

If any other kits are involved, also copy their resource files to your project directory.
Find and open the project.properties file in your project directory and add the following code to merge the manifest files in the subprojects:
- manifestmerger.enabled=true
1. Sign in to AppGallery Connect and click My projects.
2. Find your app project and click the app that needs to integrate the HMS Core SDK.
3. Go to Project Setting > Convention. In the App information area, download the agconnect-services.json file.
4. Because the Eclipse IDE does not support the AppGallery Connect plug-in, 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, create a subclass that extends the Application subclass, for example, MyApplication.
- public class MyApplication extends Application{
- @Override
- public void onCreate() {
- super.onCreate();
- }
- // TODO: Add the following code:
- @Override
- protected void attachBaseContext(Context context) {
- super.attachBaseContext(context);
- AGConnectServicesConfig config = AGConnectServicesConfig.fromContext(context);
- config.overlayWith(new LazyInputStream(context) {
- public InputStream get(Context context) {
- try {
- return context.getAssets().open("agconnect-services.json");
- } catch (IOException e) {
- return null;
- }
- }
- });
- }
- // TODO: End
- }
After that, import the following classes:
- import java.io.IOException;
- import java.io.InputStream;
- import com.huawei.agconnect.config.AGConnectServicesConfig;
- import com.huawei.agconnect.config.LazyInputStream;
- import android.app.Application;
- import android.content.Context;
- import android.util.Log;
5. 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.
- <application
- android:name=".MyApplication"
- …
- >
- …
7. In the Eclipse IDE menu bar, click Project, and then Clean.
After integrating the HMS Core Push SDK of the latest version, register Service under application in the AndroidManifest.xml file so that devices can receive the push token and messages sent by the HUAWEI Push Kit server.
Register DemoHmsMessageService:
Define the DemoHmsMessageService class (the class name is only for reference and can be customized) by extending com.huawei.hms.push.HmsMessageService, and implement its methods.
- <service
- android:name=".DemoHmsMessageService"
- android:exported="false">
- <intent-filter>
- <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
- </intent-filter>
- </service>
Set exported to false.
Configure obfuscation scripts before compiling the APK to prevent the HMS SDK from being obfuscated. If obfuscation arises, the HMS SDK may not function properly.
The configuration file in Android Studio is proguard-rules.pro, and that in Eclipse is proguard-project.txt.
1. Open the obfuscation script file of your project.
2. Add configuration to exclude the HMS SDK from obfuscation.
- -ignorewarning
- -keepattributes *Annotation*
- -keepattributes Exceptions
- -keepattributes InnerClasses
- -keepattributes Signature
- -keepattributes SourceFile,LineNumberTable
- -keep class com.hianalytics.android.**{*;}
- -keep class com.huawei.updatesdk.**{*;}
- -keep class com.huawei.hms.**{*;}
3. If you have used AndResGuard, add it to the allowlist in the obfuscation script file.
- "R.string.hms*",
- "R.string.connect_server_fail_prompt_toast",
- "R.string.getting_message_fail_prompt_toast",
- "R.string.no_available_network_prompt_toast",
- "R.string.third_app_*",
- "R.string.upsdk_*",
- "R.layout.hms*",
- "R.layout.upsdk_*",
- "R.drawable.upsdk*",
- "R.color.upsdk*",
- "R.dimen.upsdk*",
- "R.style.upsdk*",
- "R.string.agc*"