目录

1. Configuring App Information in AppGallery Connect

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

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.

Creating an App

Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project. Configure basic app information as follows:

Notice:

If you want to integrate the in-app purchase capability of the HMS SDK, make sure that the APK name ends with .HUAWEI or .huawei. Otherwise, the app will fail the review process.

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 HMS Core (APK), you must locally generate the 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 (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 in the C drive.


2. Run keytool -list -v -keystore <keystore-file> and respond as prompted.

In the preceding command, <keystore-file> indicates the complete path to the app's signature file.

Example:

  1. >keytool -list -v -keystore E:\HmsSample\android.keystore

3. Obtain the SHA-256 fingerprint from the result.

          


Configuring the Signing Certificate Fingerprint

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

2.Find your app project, and click the desired app name.

3.Go to Project Setting > General information. In the App information area, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA256 certificate fingerprint.

4. After completing the configuration, click . The configuration will take effect in about 15 minutes.

Enabling Required Services

2. Integrating the HMS SDK

2.1 Integrating the HMS SDK in Your Android Studio Project

If you are using Android Studio, you can integrate your HMS SDK by using the Maven repository. Before you start developing an app, integrate the HMS SDK into your Android Studio first.

To remotely integrate the HMS SDK using the Maven repository, perform the following steps:

1. Add the AppGallery Connect configuration file of the app to your Android Studio.

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

(2) Find your app project and click the app that needs to integrate the HMS SDK.

(3) In the App information area on the Project Setting page, download the agconnect-services.json file.

(4) Copy the agconnect-services.json file to the app root directory.

2. Add the Maven repository address and AppGallery Connect service dependencies in the build.gradle file of your project.

  1. maven {url 'https://developer.huawei.com/repo/'}
  2. classpath 'com.huawei.agconnect:agcp:1.2.1.300'


3. Add plug-in configuration and SDK version in the build.gradle file in the app directory.

(1) Open the build.gradle file in the app directory.

(2) Configure build dependencies. Replace {version} with the actual SDK version number, for example, implementation 'com.huawei.hms:hianalytics:4.0.2.300' and 'com.huawei.hms:dtm-api:4.0.4.300'.

  1. implementation 'com.huawei.hms:hianalytics:{version}'
  2. implementation 'com.huawei.hms:dtm-api:{version}'

(3) Add the AppGallery Connect plug-in dependency to the end of the file.

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

4. Click Sync Now or Sync Project with Gradle Files to build a project. If an error occurs, check the network connection and the configurations in the build.gradle file.

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.

Downloading the SDK

1. Integrate the HiAnalytics SDK before you integrate the DTM SDK. For details about how to integrate the HiAnalytics SDK, visit the following link: HUAWEI Analytics Kit Development Guide

2.Download the HMS Base SDK and DTM SDK, and decompress the ZIP packages.

(1). HMS Base SDK: HMS Base SDK

(2). DTM SDK for Eclipse: Eclipse SDK Download

3. Go to File > Import to import all SDK projects to your workspace.

(1) Go to Android > Existing Android Code Into Workspace and click Next.

(2) 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.

Adding Project Dependencies

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

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

3. As the XML file in the Eclipse IDE does not support the dollar sign ($), replace ${applicationId} in the AndroidManifest.xml file of the dtm-api project with your app package name.

  1. </application>
  2.   <activity
  3.       android:name="com.huawei.hms.dtm.PreviewActivity"
  4.       android:exported="true"
  5.       android:noHistory="true" >
  6.       <meta-data
  7.           android:name="hwc-theme"
  8.           android:value="androidhwext:style/Theme.Emui" />
  9.       <intent-filter>
  10.           <data android:scheme="dtm.configuration.${applicationId}" />
  11.           <action android:name="android.intent.action.VIEW" />
  12.           <category android:name="android.intent.category.DEFAULT" />
  13.           <category android:name="android.intent.category.BROWSABLE" />
  14.       </intent-filter>
  15.   </activity>
  16. </application>

Copying the Resource File of the DTM SDK to Your App Project Directory

Copy the resource file in the assets directory of the dtm-core project to the assets directory of your app project.

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

3. Configuring Obfuscation Scripts

Before building the APK, configure obfuscation scripts to prevent HUAWEI Analytics Kit and DTM from being obfuscated. If obfuscation arises, HUAWEI Analytics and DTM may not function properly.

1. Open the obfuscation script file of your project. The configuration file is proguard-rules.pro for Android Studio and proguard-project.txt for Eclipse.

2. Add configurations to exclude HUAWEI Analytics Kit and DTM from obfuscation.

  1. -dontwarn com.huawei.hms.**
  2. -keep interface com.huawei.hms.analytics.type.HAEventType{*;}
  3. -keep interface com.huawei.hms.analytics.type.HAParamType{*;}
  4. -keep class com.huawei.hms.analytics.HiAnalyticsTools{
  5. public static void enableLog();
  6. public static void enableLog(int);
  7. }
  8. -keep class com.huawei.hms.analytics.HiAnalyticsInstance{*;}
  9. -keep class com.huawei.hms.analytics.HiAnalytics{*;}
  10. -keep class com.huawei.hms.feature.** {public *;}
  11. -keep public class com.huawei.hms.common.** {public *;}
  12. -keep class com.huawei.hms.analytics.internal.filter.EventFilter{
  13. public void logFilteredEvent(java.lang.String, android.os.Bundle);
  14. public java.lang.String getUserProfile(java.lang.String);
  15. }
  16. -keep public class com.huawei.hms.dtm.EventFilter {
  17. public <fields>;
  18. public <methods>;
  19. }

3. If you have used AndResGuard, add it to the whitelist in the obfuscation script 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*",
  13. "R.string.agc*"