HMS Unity Plugin Integration

Kayahan Başkeser
Huawei Developers
Published in
5 min readSep 10, 2020

In this article, I will mention about HMS Unity Plugin Integration. I will explain step by step how to integrate the HMS Unity Plugin into the unity project.

First of all, currently HMS Unity Plugin supports 5 kits. All kits will be added in the following days. You can see the supported HMS kits below. (HMS Unity Plugin v1.1.2)

  • Account Kit
  • In App purchases
  • Ads Kit : Interstitial and rewarded videos
  • Push Kit
  • Game Kit : Leaderboards and achievements

This plugin have two branch for Unity versions.

  • Download plugin from this for Unity version 2019.x.
  • Download plugin from this for Unity version 2018.x .

You can access the HMS Unity plugin from the link above.

Lets start to plugin integration

1- Register Huawei Developer

To use HMS kits, you need to register on the Huawei Developer website. If you have an account, you can skip this step. Sign in with your account.

2-Create an app in AppGallery Connect

In this step, we will create an app in App Gallery Connect and do the necessary configurations.

First, let’s login to the Huawei Developer website and click on the console section.

Then, click on the AppGallery Connect section and access the AppGallery Connect.

Here we click on the my project section and we will create a project for our project.

Click on Add Project and type a name for your project.

After our project is created, we need to add an app to our project by clicking on the add app.

We need to enter app name, package name, app category and default language in this section.

If you are going to use IAP (In-App Purchases) in your application, package name must end with “.HUAWEI” or “.huawei”

In app category part, we select the game and set our default language according to ourselves.

After creating app, let’s download the agconnect-services.json file and skip the other steps. (We will use this json file in next steps)

3- Import Plugin and Configure

Before starting this step, let’s download the HMS Unity Plugin and import it to our unity project with the import package option. (download link)

After importing the HMS Unity Plugin, we need to edit 3 parameter in AndroidManifest.xml file. There are two way to edit.

1- w/ Huawei Menu

When we click on Huawei tab, it will want 3 parameters. These are package-name, app id and cp id. You can find this information from the file agconnect-service.json we downloaded from the network.

agconnect-service.json

2- Change Manually

We open the AndroidManifest.xml file in the (Assets / Plugin / Android /AndroidManifest.xml) path and change it manually.

After editing the AndroidManifest file, we delete the agconnect-services.json file in the (Assets/Huawei/agconnect-services.json) path and put the agconnect-services.json file we downloaded from the AppGallery Connect. I mean we need to replace with new agconnect-services.json file.

After then, we need to modify the android minimum SDK to 21. And we change the default package name.

Finally, we need to create a keystore for our project.

And we create sha-256 fingerprints with the keystore we created before with the command below.

keytool -list -v -keystore D:\Android\WorkSpcae\HmsDemo\app\HmsDemo.jks

Here we are adding sha-256 certificate fingerprint into AppGallery Connect.

And so the integration is complete. Now, we can try the demo scenes in the demo folder.

and I want to mention general structure of this plugin

Huawei : In this folder, there are demos folder, dlls folder, prefabs, scripts folder and agconnect-services.json file.

Huawei / Demos : There are 6 scenes and demo scripts for demo. You can try kits easily with these scenes.

Huawei / Dlls : There is a HuaweiMobileServices.dll file. You can reach kits methods of HMS via this dll file.

Huawei / Prefabs : There are 5 prefabs for 5 kits. Prefabs contain their own scripts. For example when you want to use ads kit, you should add “AdsManager” prefab. And AdsManager prefab has scripts which Rewards Ad Manager and Interstital Ad Manager.

Huawei / Scripts : The scripts inside prefabs are here. These are like interface between dll file and demo scripts. For example, instead of calling the x method in dll, we call it here.

Plugins : There are android .aar files of HMS kits and AndroidManifest file.

Resources : There are some textures for kits demo.

I hope this article was useful.

Finally, you can ask the problems that you encountered from the Huawei Developer forum page and see the questions that were answered previously.

--

--