目录

1. Configuring App Information in AppGallery Connect

Before you start developing an app, configure app information in AppGallery Connect.

1.1 Registering as a Developer

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.

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:

1.3 Generating a Signing Certificate Fingerprint

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

Please ensure that the following conditions are met:

Perform the following steps:

1. Open the command line tool and run the following command, in which<keystore-file>is the complete path to the app's signature file:

  1. keytool -list -v -keystore <keystore-file>


2. Obtain the SHA-256 fingerprint from the result. An example of the result is as follows:

  1. Alias name: <alias-name>
  2. Creation date: Aug 29, 2019
  3. Entry type: PrivateKeyEntry
  4. Certificate chain length: 1
  5. Certificate[1]:
  6. Owner: CN=Android Debug, OU=hua, C=zg
  7. Issuer: CN=Android Debug, OU=hua, C=zg
  8. Serial number: 1e46890c
  9. Valid from: Thu Aug 29 21:09:44 CST 2019 until: Mon Jan 14 21:09:44 CST 2047
  10. Certificate fingerprints:
  11.         MD5:  EC:29:9E:ED:18:35:E0:A0:93:EA:AD:E2:D9:4D:B7:6A
  12.         SHA1: E6:6B:61:C9:E5:86:81:E7:3A:7A:86:11:87:FB:DD:B6:2F:72:9D:80
  13.         SHA256: 39:B1:5E:52:70:8C:07:6D:5A:F7:0B:96:8B:D1:77:A0:8F:CA:09:08:72:90:FD:2A:1E:DB:9A:6C:2F:4E:B5:97
  14. Signature algorithm name: SHA256withRSA
  15. Subject Public Key Algorithm: 2048-bit RSA key
  16. Version: 3

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 fromGenerating a Signing Certificate Fingerprint.

4. After completing configuration, click.

2. Integrating HMS SDK

To download or use HUAWEI Location Kit, you must agree to the HUAWEI Developer Service Agreement, HUAWEI APIs Use Agreement, and AppGallery Connect Data Processing Addendum. You understand and undertake that downloading or using said HUAWEI Location Kit shall be deemed that you have agreed to all the preceding agreements, and you will fulfill and assume the legal responsibilities and obligations in accordance with said agreements.


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

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

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

a. Sign in toAppGallery Connectand 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.

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

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

  1. allprojects {
  2.            repositories {
  3.                      maven {url 'https://developer.huawei.com/repo/'}
  4.            }
  5.        }  
  6. buildscript {
  7.            repositories {
  8.                      maven {url 'https://developer.huawei.com/repo/'}
  9.            }
  10.            dependencies  {
  11.                      classpath 'com.huawei.agconnect:agcp:1.2.1.301'
  12.            }
  13.        }
NOTE:
The Maven repository address cannot be visited from a browser. It can only be configured in the IDE.

3.  Add compile dependencies.

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

b.   Configure compile dependencies.

  1. dependencies {          
  2.           implementation 'com.huawei.hms:location:{version}'
  3. }
NOTE:

Replace {version} with the actual SDK version number, for example:

implementation 'com.huawei.hms:location:4.0.4.300'.

c.  Add the AppGallery Connect plug-in dependency to the file header.

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

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

1.Downloading the SDK

Click here to download the .zip packages of the HMS Base SDK and HMS Location SDK.

Import all SDK projects to your workspace.

Decompress the hmssdk-eclipse-{version}.zip and locationsdk-eclipse-{version}.zip packages.

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.Adding Project Dependencies

  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>

3.Copying the Properties Files to Your App Project Directory

The Eclipse IDE cannot automatically merge the assets directories. Copy the properties files in the assets directory of the subprojects to the assets directory of your project. The following table lists the properties files to be copied.

SubprojectProperties File
HMSSdkStats

hianalytics_njjn, grs_sdk_global_route_config_opensdkService.json

Update

updatesdkcas.bks

Network-grs

grs_sdk_server_config.json, grs_sp.bks


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.

5 Configuring the App ID in the AndroidManifest.xml File

a. Open the AndroidManifest.xml file in your app project directory.

b. Configure your app ID.

Replace123456789 with the app ID that you requested from HUAWEI Developer.

  1. <meta-data
  2.    android:name="com.huawei.hms.client.appid"
  3.    android:value="123456789" />

6 Adding the AppGallery Connect Configuration File

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

2. Find your app from the list and click the app name.

3. Go to Develop>Overview>App information.

4. Click agconnect-services.json to download the configuration file.

5. 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.

The configuration file in Android Studio is proguard-rules.pro, and that in Eclipse is proguard-project.txt.

1. Open the obfuscation configuration file of your Android 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.**{*;}

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

  1. "R.string.hms*",
  2. "R.string.connect_server_fail_prompt_toast",
  3. "R.string.getting_message_fail_prompt_toast",
  4. "R.string.no_available_network_prompt_toast",
  5. "R.string.third_app_*",
  6. "R.string.upsdk_*",
  7. "R.layout.hms*",
  8. "R.layout.upsdk_*",
  9. "R.drawable.upsdk*",
  10. "R.color.upsdk*",
  11. "R.dimen.upsdk*",
  12. "R.style.upsdk*