🤝 How to integrate HMS Unity Plugin and Google AdMob Together to Display Huawei Ads

Hilal Tepecik
Huawei Developers
Published in
6 min readMar 23, 2023
Image by Carlos / Saigon — Vietnam from Pixabay

Introduction🌟

As a developer, integrating ads in your app can be a great way to monetize it and generate revenue. AdMob/Google Ads mediation is a popular platform many developers use to display ads in their apps. However, if you’re looking to reach a wider audience and maximize your app’s revenue potential, you may want to consider integrating Huawei Ads with AdMob/Google Ads mediation in Unity using HMS Unity Plugin. In this article, we will guide you through the process!

What is HMS Unity Plugin? 🤔

HMS Unity Plugin is a plugin that allows developers to integrate Huawei Mobile Services (HMS) with Unity. HMS provides a wide range of services, including Huawei Ads, which can be integrated with AdMob/Google Ads mediation using the HMS Unity Plugin. By integrating Huawei Ads, developers can reach a wider audience and generate more revenue.

The benefits of using the HMS Unity Plugin include the following:

  • 🤝💻💼 — Easy integration with HMS services
  • 🚀📈💪 — Improved app performance and stability
  • 💰💸💵 — Increased revenue potential
  • 🆕🔥📱 — Access to new features and services

Prerequisites: 📋

Before diving into the integration of HMS Unity Plugin and Google AdMob, make sure you have successfully completed the following prerequisite:

  • Mediation Creation: Ensure that you have set up mediation groups and Ad Units in your Google AdMob account and properly configured Huawei Ads as a mediation network. This will enable you to display ads from both platforms seamlessly. 🔄🔗

Now lets get into the part of integrating Huawei Ads with AdMob/Google Ads mediation in Unity using the HMS Unity Plugin. For this purpose, we will provide you with 6 easy steps.

  1. 🔧 Install Google Mobile Ads SDK to enable AdMob functionality.
  2. ⚙️ Configure Unity project settings for custom Gradle files.
  3. 🌐 Import and adjust the HMS Unity Plugin for your project.
  4. 📝 Modify Gradle files with necessary code snippets and save.
  5. ✅ Enable the Ads Kit in the HMS Unity Plugin.
  6. 🖼️ Display ads from both Google AdMob and HMS Unity Plugin.

So Let’s get started!

1️⃣ Step 1: Install Google Mobile Ads SDK 🔧

The first step in this integration process is to install the Google Mobile Ads SDK into your Unity project. This SDK provides the tools needed to display ads from Google AdMob in your app. Simply follow the official Google AdMob documentation for Unity to get started.

Admob Mobile SDK

If you do not make your development on XCode delete Google.IOSResolver.dll to not get an error relating XCode.

Google.IOSResolver.dll

2️⃣ Step 2: Configure Your Project Settings ⚙️

Next, head over to your Unity Editor and follow these steps:

  • Click on “Edit” and then “Project Settings.”
  • Navigate to “Player” and then “Publishing Settings.”
  • Check the boxes for “Custom Main Gradle”, “Custom Base Gradle”, and “Custom Gradle Properties.”
“Custom Main Gradle”, “Custom Base Gradle”, “Custom Gradle Properties.”

These settings ensure that your project is prepared for integration.

3️⃣ Step 3: Install the HMS Unity Plugin and Adjust the Project 🌐

Download and import the HMS Unity Plugin into your project. Once you’ve imported the plugin, make sure to adjust your project settings as needed to accommodate the HMS integration. Detailed instructions can be found in the official HMS Unity Plugin documentation.

4️⃣ Step 4: Modify Gradle Files and Save 📝

To ensure seamless compatibility between Google AdMob and the HMS Unity Plugin, you’ll need to add some specific code snippets to your Gradle files. Go to Assets -> Plugins -> Android

Note: Before Unity 2019.2, there is only one Gradle template, which is Custom Gradle Template.

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. The 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:

As I write this article the latest version is 2.0.2, so the code snippet would be;

Lastly, open gradleTemplate.properties and make sure to add the following lines:

5️⃣ Step 5: Enable Ads Kit in the HMS Unity Plugin ⚙️

Now, go back to the Unity Editor and follow these steps:

  • Click on “Huawei.”
  • Navigate to “Kit Settings.”
  • Enable the “Ads Kit” option.
HMS Unity Plugin Kits

This will ensure the HMS Unity Plugin is ready to display Huawei ads in your app.

6️⃣ Step 6: Display Huawei Ads 🖼️

With the integration complete, you can now display ads. Here is a code example for displaying banner ads. Don’t forget the supported Ad types are Banner, Interstitial and Rewarded for Huawei ads. You can find more examples by clicking on each ad type in previous sentence.

If you attach this script to a game object in the scene and build it for the device you use, you will have Huawei Ads ready for your project.

💥If you get the java.lang.UnsupportedOperationException error, which is a common error when building, replace it with an API Level that is compatible with the device you are using the minimum API for.

java.lang.UnsupportedOperationException

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

The minimum API level can be as low as 21. The device I use supports maximum of 30.

Please refer to these documents for further explanation.💥

Here are two real banner ads from Huawei Ads Using Admob Mediation 🔮

Huawei Ads Displayed via Admob
Huawei Ads Displayed via Admob

Conclusion🎉

In conclusion, integrating Huawei Ads with AdMob/Google Ads mediation in Unity using HMS Unity Plugin can be a simple and straightforward process if you follow the steps mentioned above.

By combining the strengths of AdMob/Google Ads mediation and Huawei Ads, you can reach a wider audience and achieve higher ad revenue. With the help of the HMS Unity Plugin, you can easily integrate Huawei Ads and enjoy its benefits!🖖🏽

We hope this article has been helpful in guiding you through the process of integrating Huawei Ads with AdMob/Google Ads mediation in Unity using HMS Unity Plugin. If you have any questions or comments, please feel free to leave them below.

See you in another article!

Image by Gerd Altmann from Pixabay

References

--

--

Hilal Tepecik
Huawei Developers

Game and SDK Developer @Huawei - Unity, Unreal, HMS Unity Plugin, XR Interactions Toolkit