In this section, you will create a project and an app in AppGallery Connect.

  1. Sign in to AppGallery Connect and click My projects.
  2. On the page displayed, click Add project.
  3. On the New project page, enter a project name and click OK.
  4. On the General information tab page, click Add app.
  5. On the Add app page, set Platform and Device, enter an app name and package name, select an app category (App or Game) and default language as needed, and click OK.
  6. View app information such as the allocated app ID and client secret in the App information area on the General information tab page after app creation.

In this section, you will create an Android Studio project for your app. During the creation, you will need to use the app name and package name that you have specified in AppGallery Connect.

  1. Start Android Studio and go to File > New > New Project.
  2. On the Choose your project page, click Empty Activity and then Next.
  3. On the Configure your project page, enter your app name and package name (configured in AppGallery Connect) in the Name and Package name text boxes, set Save location and Minimum API level, and click Finish. You have now created a project for your app.

In this section, you will create a signing certificate file and use it to sign your APK in Android Studio. This signing certificate file will be used to generate an SHA-256 fingerprint later.

  1. Go to Build > Generate Signed Bundle/APK in Android Studio.
  2. On the Generate Signed Bundle or APK page, select APK and click Next.
  3. If you already have a signing certificate file, click Choose existing, select the signing certificate file, and enter the key store password, key alias, and key password of the file. Then, click Next.

    If you do not have a signing certificate file, click Create new.

    On the page displayed, set related parameters including Key store path, Password, and Alias.

    After the signing certificate file is created successfully, the Generate Signed Bundle or APK page will be displayed, showing the signing certificate file information. Click Next on this page.

  4. On the page displayed, select V1 and V2 next to Signature Versions, and click Finish. A signed APK will be generated. (This APK can be uploaded to AppGallery Connect to automatically obtain the app package name.)

In this section, you will generate an SHA-256 fingerprint using the signing certificate file and keytool provided by the JDK.

In this section, you will configure the generated SHA-256 certificate fingerprint in AppGallery Connect.

  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 settings > General information. In the App information area, click Add under SHA-256 certificate fingerprint, and enter the obtained SHA-256 certificate fingerprint.
  4. Click Save.
  1. On the Project settings page, click the Manage APIs tab.
  2. On the Manage APIs tab page, toggle on switches of the services to be enabled.

Adding the AppGallery Connect Configuration File of Your App

  1. Sign in to AppGallery Connect, go to Project settings > General information. In the App information area, download the agconnect-services.json file.
  2. 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.

Gradle plugin earlier than 7.0

Gradle plugin 7.0

Gradle plugin 7.1 or later

Adding the AppGallery Connect Plugin Configuration

  1. Open the app-level build.gradle file (usually app/build.gradle).
  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' }
  1. Copy the generated signing certificate file HmsDemo.jks to your app's root directory and open the app-level build.gradle file (usually app/build.gradle).
  2. Add signing information to the android block in the build.gradle file.
    signingConfigs { release { storeFile file('HmsDemo.jks') keyAlias 'hmsdemo' keyPassword '123456' storePassword '123456' v1SigningEnabled true v2SigningEnabled true } } buildTypes { release { signingConfig signingConfigs.release minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { signingConfig signingConfigs.release debuggable true } }

Click Sync Now to synchronize the project.

If "completed successfully" is displayed, the project is synchronized successfully. Integration preparations are now completed.

Code copied