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

Documents from this version have been archived, and will not continue to be maintained. Please use the latest version.

HMS Core GuidesAwareness KitApp DevelopmentPreparations

Preparations

1. Configuring App Information in AppGallery Connect

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

1.1 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.

1.2 Creating an App

Create an app by referring to Creating a Project and Creating an App in the Project. Special configurations are as follows:

  • Platform: Select Android.

  • Device: Select Mobile phone.

  • App category: App or Game.

1.3 Set the data storage location. 

For details, see Setting Data Storage Location at the AppGallery Connect help center.

1.4 Enabling Required Services

Enable HUAWEI Awareness Kit. For details, please refer to Enabling Services.

1.5 Generating a Signing Certificate Fingerprint

A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core through the HMS SDK. Before using the HMS Core, you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect.

Please ensure that the following conditions are met:

  • You have created the app's signature file.

  • The JDK has been installed on your PC.

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 (x86) in the C drive.

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

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

Example:

Collapse
Word wrap
Dark theme
Copy code
  1. C:\Program Files (x86)\Java\jdk1.7.0_25\bin>keytool -list -v -keystore
  2. E:\HMS_SDK_2.5.1.300\Sample\HMSSdkSample_2.5.1.300_AS\HmsSample\android.keystore.jks

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

1.6 Configuring the Signing Certificate Fingerprint

1. Sign in toAppGallery Connect and select Myprojects.

2. Find your project from the project list and click the app on the project card.

3. On the Project Setting page, set SHA-256 certificate fingerprint to the SHA-256 fingerprint that is generated from the preceding section of Generating a Signing Certificate Fingerprint.

4. After completing configuration, click .

Integrating the HMS SDK

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.

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

    a. Sign in to AppGallery Connect and select My projects.

    b. Find your project from the project list and click the app on the project card.

    c. On the Project Setting page, click agconnect-services.json to download the configuration file.

    d. Copy the agconnect-services.json file to the app root directory.

2. Configure the Maven repository address for the HMS SDK.

    a. Open the build.gradle file in the root directory of your Android Studio project.

    b. Go to allprojects > repositories and configure the Maven repository address for the HMS SDK.

Collapse
Word wrap
Dark theme
Copy code
  1. allprojects {
  2.    repositories {
  3.        google()
  4.        jcenter()
  5.        maven {url 'https://developer.huawei.com/repo/'}
  6.    }
  7. }

    c. Go to buildscript > repositories and configure the Maven repository address for the HMS SDK.

Collapse
Word wrap
Dark theme
Copy code
  1. buildscript {
  2.    repositories {
  3.        google()
  4.        jcenter()
  5.        maven {url 'https://developer.huawei.com/repo/'}
  6.    }
  7. }
NOTE:
The Maven repository address cannot be accessed from a browser. It can only be configured in the IDE.

    d. Go to buildscript  > dependencies and add dependency configurations.

Collapse
Word wrap
Dark theme
Copy code
  1. buildscript{
  2.    dependencies {
  3.         classpath 'com.huawei.agconnect:agcp:1.2.1.301'
  4.    }
  5. }

3. Add build dependencies.

    a. Open the build.gradle file in the app directory.

    b. Add the following configuration to the build.gradle file:

Collapse
Word wrap
Dark theme
Copy code
  1. compileOptions {
  2.    sourceCompatibility = 1.8
  3.    targetCompatibility = 1.8
  4. } 

    c. Configure build dependencies under dependencies and replace {version} with the actual SDK version number, for example, implementation  'com.huawei.hms:awareness:1.0.4.301'.

Collapse
Word wrap
Dark theme
Copy code
  1. dependencies{
  2.  implementation 'com.huawei.hms:awareness:{version}'
  3. }

    d. Add the AppGallery Connect plug-in dependency to the file header.

Collapse
Word wrap
Dark theme
Copy code
  1. apply plugin: 'com.huawei.agconnect'
Note:
The apply plugin: 'com.huawei.agconnect' configuration must be added after the apply plugin: 'com.android.application' configuration.

4. 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. If an error occurs, check the network connection and the configurations in the build.gradle file.

Configuring Obfuscation Scripts

Before building the APK, configure obfuscation scripts to prevent the HMS SDK from being obfuscated. If obfuscation arises, the HMS SDK may not function properly.

1. Open the obfuscation script file of your Android project.

2. Add configurations to exclude the HMS SDK from obfuscation.

Collapse
Word wrap
Dark theme
Copy code
  1. -ignorewarnings
  2. -keepattributes *Annotation*  
  3. -keepattributes Exceptions  
  4. -keepattributes InnerClasses  
  5. -keepattributes Signature  
  6. -keepattributes SourceFile,LineNumberTable
  7. -keep class com.hianalytics.android.**{*;}  
  8. -keep class com.huawei.updatesdk.**{*;}  
  9. -keep class com.huawei.hms.**{*;}

3. If you have used AndResGuard, add it to the allowlist in the obfuscation script file.

Collapse
Word wrap
Dark theme
Copy code
  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*"


This page may contain third-party content. For details, click here.