We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Integrating the HMS Core 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

If you have enabled certain services in AppGallery Connect, add the agconnect-services.json file to 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 your app's root directory.

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.

NOTE

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.

  • Gradle plugin earlier than 7.0
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. Add the AppGallery Connect plugin and the Maven repository.
      • Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
      • Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
      • If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration.
      buildscript {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
          dependencies {
              ...
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
      
      allprojects {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
      } 
  • Gradle plugin 7.0
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. Add the AppGallery Connect plugin and the Maven repository.
      • Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
      • Go to buildscript > dependencies and add Android Gradle plugin configurations.
      • If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration.
      buildscript {
          repositories {
              google()
              jcenter()
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
          dependencies {
              ...
              // Add the Android Gradle plugin configuration. You need to replace {version} with the actual Gradle plugin version, for example, 7.0.1.
              classpath 'com.android.tools.build:gradle:{version}'
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
    3. Open the project-level settings.gradle file and configure the Maven repository address for the HMS Core SDK.
      dependencyResolutionManagement {
          ...
          repositories {
              google()
              jcenter() 
              // Configure the Maven repository address for the HMS Core SDK.
              maven {url 'https://developer.huawei.com/repo/'}
          }
      }
  • Gradle plugin 7.1 or later
    1. Open the build.gradle file in the root directory of your Android Studio project.

    2. Go to buildscript > dependencies and add Android Gradle plugin configurations.
      If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plugin configuration.
      buildscript {
          dependencies {
              ...
              // Add the Android Gradle plugin configuration. You need to replace {version} with the actual Gradle plugin version, for example, 7.1.1.
              classpath 'com.android.tools.build:gradle:{version}'
              // Add the AppGallery Connect plugin configuration. Please refer to AppGallery Connect Plugin Dependency to select a proper plugin version. 
              classpath 'com.huawei.agconnect:agcp:1.6.0.300'
          }
      }
      plugins {
          ...
      }
    3. Open the project-level settings.gradle file and configure the Maven repository address for the HMS Core SDK.
      pluginManagement {
          repositories {
              gradlePluginPortal()
              google()
              mavenCentral()
              // Configure the Maven repository address for the HMS Core SDK.
              maven { url 'https://developer.huawei.com/repo/' }
          }
      }
      dependencyResolutionManagement {
          ...
          repositories {
              google()
              mavenCentral()
              // Configure the Maven repository address for the HMS Core SDK.
              maven { url 'https://developer.huawei.com/repo/' }
          }
      }

Adding Build Dependencies

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

  2. Add build dependencies in the dependencies section.
    dependencies{ 
      implementation 'com.huawei.hms:identity:{version}' 
     }
    NOTE

    Replace {version} with the actual SDK version number, for example, implementation 'com.huawei.hms:identity:6.13.0.300'. For details about the version number, please refer to Version Change History.

  3. 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'
      }

Defining Multi-language Settings

  • 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.
    1. Open the app-level build.gradle file of your project.

    1. Go to android > defaultConfig, add resConfigs, and configure the supported languages as follows:
      android {
          defaultConfig {
              ...
              resConfigs "en", "zh-rCN", "Other languages supported by your app"
          }
      }        

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

Synchronizing the Project

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.

NOTE

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

Search
Enter a keyword.