1. Creating a Project and App in AppGallery Connect
In this section, you will create a project and an app in AppGallery Connect.
- Sign in to AppGallery Connect and click My projects.
- On the page displayed, click Add project.
- On the New project page, enter a project name and click OK.
- On the General information tab page, click Add app.
- 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.
- 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.
2. Creating an Android Studio Project
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.
- Start Android Studio and go to File > New > New Project.
- On the Choose your project page, click Empty Activity and then Next.
- 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.
3. Generating a Signing Certificate
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.
- Go to Build > Generate Signed Bundle/APK in Android Studio.
- On the Generate Signed Bundle or APK page, select APK and click Next.
- 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.
- 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.)
4. Generating a Signing Certificate Fingerprint
In this section, you will generate an SHA-256 fingerprint using the signing certificate file and keytool provided by the JDK.
- Windows
a) Open the command-line interface (CLI) using the cmd command, and run the cd command to go to the directory where keytool.exe is located. In the following example, the JDK is installed in the Program Files folder in drive C.cd C:\Program Files\Java\jdk\bin
b) Run keytool -list -v -keystore<keystore-file> and respond as prompted. In the command, <keystore-file> indicates the absolute path to the app's signing certificate.
Example:keytool -list -v -keystore C:\TestApp.jks
c) Obtain the SHA-256 certificate fingerprint. - macOS
a) Open Terminal.
b) Run keytool -list -v -keystore<keystore-file> and respond as prompted. In the command, <keystore-file> indicates the absolute path to the app's signing certificate.
Example:keytool -list -v -keystore /Users/admin/Downloads/HmsDemo.jks
c) Obtain the SHA-256 certificate fingerprint.
5. Configuring the Signing Certificate Fingerprint in AppGallery Connect
In this section, you will configure the generated SHA-256 certificate fingerprint in AppGallery Connect.
- Sign in to AppGallery Connect and click My projects.
- Find your app project, and click the desired app name.
- 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.
- Click Save.
6. Enabling Required Services in AppGallery Connect
- On the Project settings page, click the Manage APIs tab.
- On the Manage APIs tab page, toggle on switches of the services to be enabled.
7. Adding Configurations
Adding the AppGallery Connect Configuration File of Your App
- Sign in to AppGallery Connect, go to Project settings > General information. In the App information area, download the agconnect-services.json file.
- 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 |
- Gradle plugin earlier than 7.0
- Open the build.gradle file in the root directory of your Android Studio project.
- 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. You are advised to use the latest 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/'} } }
- Open the build.gradle file in the root directory of your Android Studio project.
- Gradle plugin 7.0
- Open the build.gradle file in the root directory of your Android Studio project.
- Add the AppGallery Connect plugin and the Maven repository.
- Go to buildscript > 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. You are advised to use the latest plugin version. classpath 'com.huawei.agconnect:agcp:1.6.0.300' } }
- 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/'} } }
- Open the build.gradle file in the root directory of your Android Studio project.
- Gradle plugin 7.1 or later
- Open the build.gradle file in the root directory of your Android Studio project.
- 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 AppGallery Connect plugin configuration. You are advised to use the latest plugin version. classpath 'com.huawei.agconnect:agcp:1.6.0.300' } }
- 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/' } } }
- Open the build.gradle file in the root directory of your Android Studio project.
Adding the AppGallery Connect Plugin Configuration
- Open the app-level build.gradle file (usually app/build.gradle).
- 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' }
- Method 1: Add the following configuration under the declaration in the file header:
8. Configuring the Signing Information for Your Project
- 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).
- 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 } }
9. Synchronizing the Project
Click Sync Now to synchronize the project.
If "completed successfully" is displayed, the project is synchronized successfully. Integration preparations are now completed.