[Huawei Developers] ask011:
1.1 Service Introduction​

Account Kit provides you with simple, secure, and quick sign-in and authorization functions. Instead of entering accounts and passwords and waiting for authentication, users can just tap the Sign in with HUAWEI ID button to quickly and securely sign in to your app with their HUAWEI IDs.

1.2 Version Change History​

1.2.1 Version Dependencies​

l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 or later, the user will be directed to install it when it is called by your app. User devices need to run EMUI 3.0 or later or Android 4.4 or later (API level 19 or later). The Unity version must be 2018.4.25 or later.

1.3 Preparations​

1.3.1 Importing Unity Assets​

1. Open Asset Store.

Go to Window > Asset Store in Unity.

2. Search for the Huawei HMS AGC Services asset. Download and then import it.

3. Import the asset to My Assets, with all services selected.

4. Search for the Unity Distribution Portal (UDP) asset in Asset Store. Download and then import it.

5. Change the package name.

Go to Edit > Project Settings > Player, click the Android icon, and go to Other Settings in Unity. Then, set Package Name.

The default package name is com.${Company Name}.${Product Name}. You need to change the package name, and the app will be released to AppGallery with the new name.

1.3.2 Generating .gradle Files​

1. Enable project gradle.

Go to Edit > Project Settings > Player in Unity, click the Android icon, and go to Publishing Settings > Build.

Enable Custom Base Gradle Template.

Enable Custom Launcher Gradle Template.

Enable Custom Main Gradle Template.

Enable Custom Main Manifest.

2. Signature

You can use an existing keystore file or create a new one to sign your app.

Go to Edit > Project Settings > Player in Unity, click the Android icon, and go to Publishing Settings > Keystore Manager > Keystore... > Create New.

Enter the password when you open Unity. Otherwise, you cannot build the APK.

1.3.3 Configuring .gradle Files​

1. Configure the baseProjectTemplate.gradle file.

allprojects {
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
}
repositories {
google()
jcenter()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
maven { url 'https://developer.huawei.com/repo/' }
}
}

2. Configure the launcherTemplate.gradle file.

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
dependencies {
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
implementation 'com.huawei.hms:base:4.0.1.300'
implementation 'com.huawei.hms:hwid:4.0.1.300'
...
}

3. Configure the mainTemplate.gradle file.

apply plugin: 'com.android.library'
apply plugin: 'com.huawei.agconnect'
dependencies {
...
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
implementation 'com.huawei.hms:base:4.0.1.300'
implementation 'com.huawei.hms:hwid:4.0.1.300'
...
}

1.3.4 Adding the agconnect-services.json File​

1. Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project.

Run keytool -list -v -keystore C:\TestApp.keyStore to generate the SHA-256 certificate fingerprint based on the keystore file of the app. Then, configure the fingerprint in AppGallery Connect.

2. Download the agconnect-services.json file and place it in the Assets/Plugins/Android directory of your Unity project.

1.3.5 Enabling Account Kit​

1. Sign in to AppGallery Connect.

2. Click My projects and find your project. Go to Build > Account Kit.

1.4 App Development​

For details, please refer to udpServiceSampleScript under Assets > HuaweiServiceDemo > Scripts in the demo package provided by Huawei.

1.4.1 Uploading Your Project to UDP​

For details about UDP, please refer to its official documents.

1.

Go to Window > Unity Distribution Portal > Settings in Unity and click Go to the Services Window.

2. Select an organization.

3. Link your project to a UDP client.

Go to Window > Unity Distribution Portal > Settings > Inspector in Unity and click Generate new UDP client.

4. Set Game Title and UDP Sandbox Test Accounts.

5. Push all the settings.

1.4.2 Testing the APK​

1. Go to File > Build Settings > Android in Unity and click Switch Platform.

1.1 Select UDP/Sample/UDPSampleScene.

1.2 Build the project. Save and install the APK.

2. Use the configured sandbox test account to initialize the APK.

2.1 Open the APK and tap Init.

2.2 Enter the configured sandbox account.

2.3 Verify that the sandbox test is successful.

1.4.3 Repacking the APK​

1. Sign in to the UDP console.

2. Click the newly created game.

3. Edit the game information and then click Release.

4. Choose HUAWEI AppGallery.

5. Set your In-App Purchases public key manually. Unity will automatically obtain other information from AppGallery Connect based on the package name.

6. Choose HUAWEI AppGallery and click Publish.

7. The UDP console repacks your APK.

8. Download the repacked APK, which supports sign-in with a HUAWEI ID.

More Information

To join in on developer discussion forums, go to Reddit

To download the demo app and sample code, go to GitHub

For solutions to integration-related issues, go to Stack Overflow

Read In Forum