Huawei Unity SDK Setup
Follow these instructions if your app is distributed on the Huawei AppGallery.
Requirements
- Android Studio
- A Huawei device with "Huawei App Gallery" installed
- Configured OneSignal App and Platform
Configure your OneSignal app and platform
Required
Before enabling push notifications, make sure your app is set up with the platforms you support— Apple (APNS), Google (FCM), Huawei (HMS), and/or Amazon (ADM). Follow the steps below to configure your OneSignal account and platform settings.
If your team already has a OneSignal account, ask to be invited as an admin role so you can configure the app. Otherwise, sign up for a free account to get started.
Details on configuring your OneSignal app (click to expand)
You can configure multiple platforms (iOS, Android, Huawei, Amazon) within a single OneSignal app.
1. Create or select your app
- Select your app and go to Settings > Push & In-App to add platforms to an existing app.
- Or create a new app by clicking New App/Website.

Example shows creating a new app.
2. Set up and activate a platform
- If creating an app, choose a recognizable app and organization name.
- Select a platform to activate.
- Click Next: Configure Your Platform.

Example setting up your first OneSignal app, org, and channel.
3. Configure platform credentials
Follow the prompts based on your platforms:
- Android: Set up Firebase Credentials
- iOS: p8 Token (Recommended) or p12 Certificate
- Amazon: Generate API Key
- Huawei: Authorize OneSignal
Click Save & Continue after entering your credentials.
4. Choose target SDK
Select your app's target SDK and click Save & Continue.

Select which SDK you are using to be navigated to the docs.
5. Install SDK and save your App ID
You’ll be shown your OneSignal App ID — make sure to save it, as you’ll need it during SDK installation.
If needed, invite a teammate or developer by clicking Invite, then click Done.

Save your App ID for SDK setup and invite any more team members.
Continue through the rest of our documentation to complete the integration.
Setup
1. Setup the OneSignal Unity SDK
Follow the OneSignal Unity SDK setup guide. Firebase / Google setup not required for app builds released to the Huawei AppGallery.
2. Huawei Setup
Huawei Platform Setup on OneSignal
Huawei Configuration File (agconnect-services.json)
From the AppGallery Connect Project List select your app.
Click on the "agconnect-services.json" button to download this file.
- Place this inside Assets/Plugins/Android/OneSignalConfig
3. Generating a Signing Certificate Fingerprint
You can skip this step if you already have added your SHA-256 certificate fingerprint to Huawei's dashboard for a different Huawei service.
Follow Generating a Signing Certificate Fingerprint
4. Add Huawei Gradle Plugin and Dependencies
Unity 2019.3 Or Newer
4a.1 Go to File -> Build Settings -> Player Settings -> Android -> Publishing Settings and click under
Custom Main Gradle Template. This will create a mainTemplate.gradle.
4a.2 On mainTemplate.gradle remove the comment
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
- Under
dependencies
addimplementation 'com.huawei.hms:push:6.3.0.304'
4a.3 Create a new file named Assets/Plugins/Android/settingsTemplate.gradle with the following contents.
import java.nio.file.Files
// This file contents should be placed at Assets/Plugins/Android/settingsTemplate.gradle
// This works around Unity's 2019.3 bug where their root build.gradle is placing buildscript under allprojects
// On it's own it doesn't create issues however doing so means including a buildscript block in any sub projects
// such as "unityLibrary" which is generated from the template Assets/Plugins/Android/mainTemplate.gradle does not work.
// It results in a build error of "Configuration with name 'compileClasspath' not found." on a lint task.
// Normally adding "lintOptions { abortOnError false }" bypasses any lint task errors however
// either due to a bug with the Android Gradle plugin or an order of operations this does seem to be applying in this case.
// Until Unity fixes their root build.gradle we will need to keep using this file to enable any additional Gradle plugins.
static void enableJetifier(Project project) {
project.ext['android.useAndroidX'] = true
project.ext['android.enableJetifier'] = true
}
static void addBuildscript(Project project) {
project.buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.huawei.agconnect:agcp:1.6.5.300'
}
}
}
static void applyPlugins(Project project) {
// Only apply to the :app project. (Unity calls this :launcher)
if (project.name != 'launcher')
return
project.afterEvaluate {
it.apply plugin: 'com.huawei.agconnect'
}
}
static void copyHMSFile(Project project) {
// Only apply to the :app project. (Unity calls this :launcher)
if (project.name != 'launcher')
return
def newFile = new File("${project.rootDir}/launcher/agconnect-services.json")
if (newFile.exists())
return
def file = new File("${project.rootDir}/unityLibrary/OneSignalConfig/agconnect-services.json")
Files.copy(file.toPath(), newFile.toPath())
}
gradle.rootProject {
it.afterEvaluate {
it.allprojects {
// Since Unity 2019.3 enabling Jetifier via mainTemplate.gradle is no longer working
// Enabling it for all gradle projects here.
enableJetifier(it)
addBuildscript(it)
applyPlugins(it)
copyHMSFile(it)
}
}
}
// Per Unity's docs /*/*INCLUDES/*/* should be at the bottom.
// https://docs.unity3d.com/Manual/android-gradle-overview.html
// However it seem to have left out this include line
include ':launcher', ':unityLibrary'
**INCLUDES**
Unity 2019.2 Or Older
4b.1 Go to File -> Build Settings -> Player Settings -> Android -> Publishing Settings and click under
Custom Gradle Template. This will create a mainTemplate.gradle.
4b.2 On mainTemplate.gradle remove the comment
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
- Under
buildscript { repositories }
addmaven { url 'http://developer.huawei.com/repo/' }
- Under
buildscript { dependencies }
addclasspath 'com.huawei.agconnect:agcp:1.6.5.300'
- Under
allprojects { repositories }
addmaven { url 'http://developer.huawei.com/repo/' }
- After adding these dependencies, add below
allprojects {}
the following
allprojects {
...
}
task copyReport(type: Copy) {
from file("$projectDir/OneSignalConfig/agconnect-services.json")
into file("$projectDir")
}
allprojects {
afterEvaluate {
for (def task in it.tasks)
if (task != rootProject.tasks.copyReport)
task.dependsOn rootProject.tasks.copyReport
}
}
- Under
dependencies
addimplementation 'com.huawei.hms:push:6.3.0.304'
- At the bottom of the file add
apply plugin: 'com.huawei.agconnect'
5. Run and test your app
Run your app on a real Huawei device to make sure your device is subscribed to notifications as a Huawei device and can receive notifications sent from the OneSignal dashboard.
6. Configure Huawei Location Service (Optional)
On mainTemplate.gradle under dependencies
add implementation 'com.huawei.hms:location:<HUAWEI HMS VERSION #>
Make sure to also add the location permission to your AndroidManifest.xml if you don't have this already
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- HMS error code reference to help debug logs and successfully integrate HMS Core SDK with the OneSignal SDK.
Updated 12 months ago