目录

Integrating the SDK

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

Adding the AppGallery Connect Configuration File of Your App

  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 settings > General information. In the App information area, download the agconnect-services.json file.

  4. Copy the agconnect-services.json file to the app's root directory of your Android Studio project.

    • Before obtaining the agconnect-services.json file, ensure that you have enabled the HUAWEI Analytics service. For details, please refer to Enabling HUAWEI Analytics.
    • If you have performed any modification such as setting the data storage location and enabling or managing some APIs, you need to download the latest agconnect-services.json file and use the file to replace the existing one in the app directory of your Android Studio project.

Configuring the Maven Repository Address for the HMS Core SDK

The procedure for configuring the Maven repository address in Android Studio is different for Gradle plugin earlier than 7.0, Gradle plugin 7.0, and Gradle plugin 7.1 or later. Click a relevant link below to find the configuration procedure for the specific Gradle plugin version.

The Maven repository address cannot be accessed from a browser. It can only be configured in the IDE. If there are multiple Maven repositories, add the Maven repository address of Huawei as the last one.

Adding Build Dependencies

  1. Open the app-level build.gradle file of your project.

  2. Add the AppGallery Connect plugin configuration in either of the following methods:

    • Method 1: Add the following configuration under the declaration in the file header:
      apply plugin: 'com.huawei.agconnect'
    • Method 2: Add the plugin configuration in the plugins block.
      plugins {
          id 'com.android.application'
          // Add the following configuration:
          id 'com.huawei.agconnect'
      }

  3. Add build dependencies in the dependencies section.

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

    Replace {version} with the actual SDK version number. For details about the Analytics Kit version number, please refer to version-change-history. For details about the DTM version number, please refer to Version Change History.

    Example: implementation 'com.huawei.hms:hianalytics:6.12.0.301' and implementation 'com.huawei.hms:dtm-api:6.6.0.308'.

(Optional) Integrating the DTM Plugin

After integrating the DTM plugin, you can dynamically inject event tracking code to the target class during app build, therefore improving the app runtime performance.

If the version in com.huawei.hms:dtm-api:version is 5.2.0.300 or later, you are advised to integrate the DTM plugin.

The plugin is available only for Android Studio projects.

After integrating the plugin, you can skip 2 in Adding Visual Events for a Fragment.

  1. Add a dependency on the DTM plugin in the project-level build.gradle file.

    buildscript {
        repositories {
            google()
            jcenter()
            // Configure the Maven repository address.
            maven {url 'https://developer.huawei.com/repo/'}
        }
        dependencies {
            ...
            // Add the DTM plugin configuration.
            classpath 'com.huawei.hms:dtm-plugin:6.1.0.300'}
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            // Configure the Maven repository address.
            maven {url 'https://developer.huawei.com/repo/'}
        }
    }

  2. Add the DTM plugin configuration in the app-level build.gradle file in either of the following methods as needed:

    • Method 1: Add the following configuration under the declaration in the file header:
      apply plugin: 'com.huawei.hms.dtm.plugin'
    • Method 2: Add the plugin configuration in the plugins block.
      plugins {
          id 'com.android.application'
          // Add the plugin configuration.
          id 'com.huawei.hms.dtm.plugin'
      }

  3. (Optional) To view the DTM plugin build logs, add the following configuration to the app-level build.gradle file:

    android {       }
    // Configure the following information.
    dtmConfig{
     // Specify whether to record DTM plugin compilation logs. true: yes; false: no.
        debug = true
    }

Synchronizing the Project

After completing the preceding configuration, click the synchronization icon on the toolbar to synchronize the project with Gradle files.

If an error occurs, check the network connection and the configuration in the Gradle files.