Android Studio: HMS Preparations for Integrating HUAWEI HMS Core
Novice Note: HMS Core Integration to Android Studio in Ubuntu 21.10 This article is the author’s notes while struggling to integrate HMS Core into Android Studio. There are “too” many notes out there, so it’s pretty tricky for a beginner to find reasonable steps to integrate HMS Core into Android Studio. Unfortunately, the HMS Core is very much needed if we want to use various HMS kits in the android applications that we develop. Please note that these steps may be incorrect.
Steps summary seems to be
- Creating a Project and App in AppGallery Connect and Android Studio
- Setup SDK
- Generating a Signing Certificate
- Generating a Signing Certificate Fingerprint
- Configuring the Signing Certificate Fingerprint in AppGallery Connect
- Enabling Required Services in AppGallery Connect
- Configuring the Signing Information for The Project
- Synchronizing the Project
The Setup
The author’s setup is:
- OS Ubuntu 21.10
- Android Studio BumbleBee 2021.1.1 Patch 2
- Huawei Developer ID, signup at developer.huawei.com
Creating a Project and App in AppGallery Connect and Android Studio
Steps to create a project in AppGallery Connect,
- login to developer.huawei.com
- click Console (on the upper right hand side)
- click AppGallery Connect
- click Add project
- Type Project Name, for example, ITTS HMS Test Project
- click OK
In Project Information, Data processing location, click ENABLE. Select Singapore and set as default. Singapore is selected as it is quite close to the author location in Jakarta.
On the top section, click Add app (blue button). Setting of this app must be the same (better simultaneously) set in Android Studio.
Setup in AppGallery Connect as in the Picture
Setup in Android Studio as in the following Picture
Note that Name and Package Name must be the same.
Setup SDK
It seems this section is the trickiest part. The author is still struggling in this section. The next page is Setup SDK
- Download file agconnect-services.json
Copy to app root directory in PC with Android Studio. From Downloads folder use the following command,
cp agconnect-services.json ~/AndroidStudioProjects/ITTSHMSTest1/app/src/
In project-level build.gradle (app > Gradle Scripts)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript{ repositories { // Add the Maven address. maven { url 'https://developer.huawei.com/repo/' } } dependencies { classpath 'com.android.tools.build:gradle:7.0.3' classpath 'com.huawei.agconnect:agcp:1.5.2.300' } } plugins { id 'com.android.application' version '7.1.2' apply false id 'com.android.library' version '7.1.2' apply false } task clean(type: Delete) { delete rootProject.buildDir }
In app-level build.gradle (app > Gradle Scripts)
plugins { .... id 'com.huawei.agconnect' } dependencies { // No longer needed // implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300' }
- Klik Next and Finish.
Generating a Signing Certificate
Next, we need to generate signing certificate from the Android Studio. It is use to sign the APK in Android Studio. This signing certificate file will be used to generate an SHA-256 fingerprint later.
In Android Studio, click Build > Generate signed Bundle/APK > Select APK > Next > Create New
Fill the following form
The Keystore Path use here is
/home/onno/AndroidStudioProjects/ITTSHMSTest1/app/ittshmstest1.jks
note the extension of the file is .jks (Java KeyStore) to store a set of cryptographic keys.
- Click Remember Password > Next.
- Select release > Finish.
Generating a Signing Certificate Fingerprint
In this section, the signing certificate SHA-256 fingerprint using keytool provided by JDK. In Ubuntu, keytool can be search by command
locate keytool
The output can be as follows, for example,
/home/onno/.jdks/openjdk-17.0.2/bin/keytool /usr/local/android-studio/jre/bin/keytool
Run keytool
cd /usr/local/android-studio/jre/bin/ ./keytool -list -v -keystore /home/onno/AndroidStudioProjects/ITTSHMSTest1/app/ittshmstest1.jks
Enter the password in menu
Enter keystore password:
The example output would be,
Keystore type: PKCS12 Keystore provider: SUN Your keystore contains 1 entry Alias name: key0 Creation date: Mar 10, 2022 Entry type: PrivateKeyEntry Certificate chain length: 1 Certificate[1]: Owner: CN=Onno Purbo, OU=Programming Lab., O=ITTS, L=Tangerang Selatan, ST=Banten, C=62 Issuer: CN=Onno Purbo, OU=Programming Lab., O=ITTS, L=Tangerang Selatan, ST=Banten, C=62 Serial number: 1a9108c3 Valid from: Thu Mar 10 17:10:08 WIB 2022 until: Mon Mar 04 17:10:08 WIB 2047 Certificate fingerprints: SHA1: 6B:70:21:B1:CA:39:22:28:66:69:65:06:73:C5:3C:C9:78:9D:EF:F7 SHA256: 4C:C1:18:F0:2D:85:A8:E3:6C:CF:30:19:16:F7:5C:A8:C4:7C:B3:77:B4:F1:68:4C:2E:8F:E8:DB:CC:7F:5D:83 Signature algorithm name: SHA256withRSA Subject Public Key Algorithm: 2048-bit RSA key Version: 3 Extensions: #1: ObjectId: 2.5.29.14 Criticality=false SubjectKeyIdentifier [ KeyIdentifier [ 0000: CA EE D4 B2 7B 97 BB 07 D3 A6 AF 2A DF 82 B7 FB ………..*…. 0010: 15 CC CF B4 …. ] ]
We need to grab the SHA-256 certificate fingerprint, in this case
4C:C1:18:F0:2D:85:A8:E3:6C:CF:30:19:16:F7:5C:A8:C4:7C:B3:77:B4:F1:68:4C:2E:8F:E8:DB:CC:7F:5D:83
Configuring the Signing Certificate Fingerprint in AppGallery Connect Having the SHA-256 certificate fingerprint, we need to go back to AppGallery Connect and paste the SHA-256 certificate fingerprint to App Information > SHA-256 certificate fingerprint as shown below,
Click Save
Enabling Required Services in AppGallery Connect After the SHA-256 certificate fingerprint saved, our job is to enable the required services. Go to developer.huawei.com > Console > AppGallery Connect > My Project > Managed API Enable the needed API as shown below
Configuring the Signing Information for The Project
Make sure .jks file is in app folder. Use, for example,
ls ~/AndroidStudioProjects/ITTSHMSTest1/app
Edit app-level build.gradle replace buildTypes{} with
signingConfigs { debug { storeFile file('ittshmstest1.jks') // PENTING!! atau path lengkap! keyAlias 'key0' keyPassword '123456' storePassword '123456' v1SigningEnabled true v2SigningEnabled true } release { storeFile file('ittshmstest1.jks') // PENTING!! atau path lengkap! keyAlias 'key0' keyPassword '123456' storePassword '123456' v1SigningEnabled true v2SigningEnabled true } } buildTypes { release { signingConfig signingConfigs.release // PENTING!! minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { signingConfig signingConfigs.release debuggable true } }
make sure storeFile, keyAlias, keyPassword, storePassword are correct.
Synchronizing the Project
In Ubuntu Android Studio, click Sync. Make sure Gradle sync finished with no error.
That’s it! Cross finger hope for the best :) ..