How to use Huawei Ads with Supported Ad Platforms in Unity ?

Enes Özdemir
Huawei Developers
Published in
4 min readOct 26, 2021

--

In this article, we are going to talk about how to use Huawei ads in unity with mediation through supported ad platforms.

Supported Platforms are Google Admob, Google Ad Manager and Mopub.

If you already integrated one of these platforms Unity SDK into your game you can easily integrate our mediation plugins to your Unity Project and start displaying Huawei Ads.

Supported formats in Unity are Banner Ads, Interstitial Ads and Rewarded Ads.

Before the integration processes in Unity make sure that you have successfully completed mediation creation parts for the platform you want to use.

If this process is completed in the related platform you can start to integrate our Mediation plugins into your project.

How to Use Huawei Mediation in Unity

  • In Unity go to File -> Build Settings
  • In Build Setting select Android and click Switch Platform

Edit -> Project Settings -> Player -> Other Settings

•In Other Settings set minimum API level to at least 21

Edit -> Project Settings -> Player -> Publishing Settings

•In Publishing Settings select “Custom Main Gradle Template”, “Custom Base Gradle Template” and “Custom Gradle Properties Template”

•This will let you override mainTemplate.gradle , baseProjectTemplate.gradle and gradleTemplate.properties files in the project

Note: Before Unity 2019.2 there is just one Gradle template which is Custom Gradle Template

•The path of the mainTemplate.gradle , baseProjectTemplate.gradle and gradleTemplate.properties files and open them in a text editor

Note: If the Unity version is lower than 2019.2 all of the following configurations will be done in mainTemplate.gradle

•Open baseProjectTemplate.gradle in a text editor and add maven lines from our mediation readme file

Note: If the Unity version is lower than 2019.2 these maven lines also have to be added to the project.repositories section in mainTemplate.gradle

Note: Minimum supported Gradle Tools version is 3.4.3.

  • Open mainTemplate.gradle in a text editor and add the following implementation lines depending on your selected platform.

For Admob/Ad Manager :

dependencies {
implementation 'com.huawei.hms:ads-prime:3.4.56.302' // If release to Google Play, then use ads-prime
implementation 'com.huawei.hms:ads-lite:13.4.62.302' // If release to AppGallery only, then use lite
implementation 'com.github.Explore-In-HMS:huawei.ads.admob_mediation:<latest_version>'
}

For MoPub :

IMPORTANT : Mobup is deprecated and changed to Applovin. You can use the following link for the current version.

  • Open gradleTemplate.properties and make sure to add the following lines:

After these configurations are completed you can display Huawei Ads.

Note: In some newer Gradle versions some parameters of aaptOptions are deprecated.

  • In case of any error on aaptOptions you can add the following line to aaptOptions in launcherTemplate.gradle which you override by enabling it from Edit -> Project Settings -> Player -> Publishing Settings.

For more details please check mediation plugins readme:

Admob / Ad Manager

Mopub

References

Huawei Ads Kit

Admob Unity

--

--