[Huawei Developers] shikkerimath:
1.1 Version Change History​

1.2 Service Introduction​

1.2.1 Overview​

This document describes how to integrate Push Kit using the official Unity asset. After the integration, your app can use the services of this Kit on HMS mobile phones.

For details about Push Kit, please visit HUAWEI Developers.

1.2.2 Restrictions​

For details, please refer to the development guide.

1.2.3 Supported Unity Versions​

Note: If the version is earlier than 2018.4.25, you can manually import assets.

1.3 Preparations​

1.3.1 Importing Unity Assets​

1. Open Asset Store in Unity.

Go to Window > Asset Store in Unity.

View attachment 5257763

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

View attachment 5257767

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

View attachment 5257769

4. Change the package name.

Go to Edit > Project Settings > Player > Android > Other Settings in Unity, and 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.

View attachment 5257771

View attachment 5257773

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.

View attachment 5257775

View attachment 5257777

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.

View attachment 5257779

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.

Configure the Maven repository address.

<p style="line-height: 1.5em;">buildscript {
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity.
// For the Gradle version preinstalled with Unity, please visit https://docs.unity3d.com/Manual/android-gradle-overview.html.
// For the official Gradle and Android Gradle Plugin compatibility table, please visit https://developer.android.com/studio/releases/gradle-plugin#updating-gradle.
// To specify a custom Gradle version in Unity, go do Preferences > External Tools, deselect Gradle Installed with Unity (recommended) and specify a path to a custom Gradle version.
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
**BUILD_SCRIPT_DEPS**
}
repositories {**ARTIFACTORYREPOSITORY**
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
}</p>

2. Configure the launcherTemplate.gradle file.

<p style="line-height: 1.5em;">// Generated by Unity. Remove this comment to prevent overwriting when exporting again.
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
dependencies {
implementation project(':unityLibrary')
implementation 'com.huawei.hms:push:4.0.3.301'
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
}</p>

3. Configure the mainTemplate.gradle file.

<p style="line-height: 1.5em;">apply plugin: 'com.android.library'
apply plugin: 'com.huawei.agconnect'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.huawei.agconnect:agconnect-core:1.2.0.300'
**DEPS**}</p>

4. Add the <service> block to the AndroidManifest.xml file.

<p style="line-height: 1.5em;"><?xml version="1.0" encoding="utf-8"?>
<!-- Generated by Unity. Remove this comment to prevent overwriting when exporting again. -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<service
android:name="com.unity.hms.push.MyPushService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
</manifest></p>

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.

View attachment 5257783

View attachment 5257785

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.

View attachment 5257787

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

View attachment 5257789

1.3.5 Enabling Push Kit​

For details, please refer to the development guide.

1.4 App Development with the Official Asset​

1.4.1 Sample Code​

Read in forum

1.4.2 Testing the APK​

1. Generate the APK.

Go to File > Build Settings > Android, click Switch Platform and then Build And Run.

View attachment 5257791

2. Create messages to be pushed in AppGallery Connect.

Sign in to AppGallery Connect and click My projects. Go to Push Kit and click Add notification.

View attachment 5257793

3. Run the APK to obtain the device token and configure it in AppGallery Connect.

View attachment 5257795

4. Check logs for data messages.

View attachment 5257797

For more details, you can go to:

l Our official website

l Our Development Documentation page, to find the documents you need

l Reddit to join our developer discussion

l GitHub to download demos and sample codes

l Stack Overflow to solve any integration problems

Read in forum