How to Add Huawei Ads to Your Games with Unity(UDP) and IronSource

Seyyid Yiğit
Huawei Developers
Published in
10 min readMar 9, 2023

--

Unity & IronSource

Introduction🎟️

Hi folks, in this article, we will learn how to add Huawei ads to our game using ironSource via Unity Distribution Portal (UDP).

Unity and ironSource signed an agreement on July 13, 2022, joining forces to provide developers with a variety of options and tools to monetize and broker networks in their games. This will allow us to have a wider and higher impression ad network. We also have the ability to manage and optimize ads from a single dashboard, making our job even easier.

⚠️Note: This guide assumes that you have a Unity and Huawei AppGallery Developer account. If you do not have an account, it is important to create one first and then continue with the guide for an uninterrupted flow.

Here we go!!!

Creating an Account on IronSource and Connecting with Unity 🖇

As a first step, we start by creating an account on IronSource. 🚦

Create IronSource Account

After creating our account, we do the confirmation process that comes to our e-mail. Then, when we log in, a screen like the one below will greet us. Here we fill in the fields according to our own application standards 🧬

Adding App

After filling in the required fields, we have our app and APP KEY. We do not need to activate ads in this step. We will look at them in detail in the following steps.🧩

Adding App

When our application addition process is completed, an area like the image below will greet us. If not, you can access this area by following Setup > Ad Units & Placement in the left side menu.

IronSource Dashboard

⚠️Note : After this step, you need to go to the Unity Portal and perform the basic steps. If you do not have an account, you need to create an account, if you do not have a project, you need to create a project. If you have done these operations, you can continue directly, but if not, you can continue below after you have done the steps to create projects and games in the How to Publish Your Games to AppGallery with UDP(Unity Distribution Portal) and the steps to connect the project in Unity Editor to Unity Portal (the part up to the image with UDP Project Connectivity Check).

Now that our basic operations on IronSource are over, we enter the Unity Portal and activate our advertising service. Here you can proceed by following the steps in the images below.👇

Unity Portal Mediation Setup
Unity Portal Mediation Setup

We have also made our advertising service ready on Unity Portal. Now we will move to the project side and make our connections through the Unity Editor.

Dude Almost

IronSource Plugin setup and Demo Application Test 🏗️

We go to the IronSource developer site and download the plugin file.

Download IronSource Plugin

After downloading our plugin file, we add the plugin to our project by following the steps in the image below.

IronSource Plugin Setup
Mobile Dependency Resolver Setup

After installing the IronSource plugin, a folder named IronSource will be created in Asset. Inside this folder is the default demo scene of IronSource. First, we will activate this scene to test our connections.

Activeted Demo Scene

After activating our demo scene, we will Resolve the project using Mobile Dependency Resolver. But there is a high probability that you will have a problem while doing this process. You can do Resolve and solve the problem by following the images below.

Mobile Dependency Resolver (First attempt error)

After getting an error, we download a file named gradlew.bat and copy it here by following the Temp > PlayServicesResolverGradle path in our project.

Grawler.bat Download and Add to Project

Then we perform the resolve operation again. 🫠

Reload Project and Dependency Resolve

As you can see in the image below, the resolve process has been completed successfully. 🎉

Dependency Resolve Operation and Successful Result

Then we build our application and test it by running it on any android phone (emulator). You can see the tests I did in the images below.

Adding Huawei Ads to IronSource

Yes, guys, after running our demo application safely, we are now starting operations to see our Huawei ads.

We log in to our AppGallery Connect account and create an API client for the Connect API from the Users and Permissions area. We will use the keys generated after this process to connect Huawei to IronSource.

After finishing the API creation process, as you can see in the image below, a Client is created with the Client ID and Key. You can download and save the Client ID and Key information if you wish, or you can come back here to learn it later.

Creating AppGallery Connect Reporting API

After completing the necessary Reporting API operations on the Huawei side, we switch to IronSource and add Huawei to our ad network by selecting the Custom Adapter option as in the images below.

Creating an IronSource Custom Adapter (Huawei)
  1. We use the key “15b993999” as the Network Key for Huawei.
  2. Instead of Client ID, we type the Client ID we created using the AppGallery Connect panel before, instead of ClientSecret and Key, we type the values in the Key field and select the Reporting API box.
Creating an IronSource Custom Adapter (Huawei)

After completing the Custom Adapter installation, we return to our AppGallery Connect panel to determine which application our ads will belong to and copy the App ID section in the image below.

Learn App ID on AppGallery Connect

After copying our App ID, we can now go to the Setup section as in the image below.

IronSource Huawei Custom Adapter Edit

After clicking Setup, we will see a screen like the images below. 🫂

🔴Rewarded Test AdUnitId => “testx9dtjwj8hp”

🟣Interstitial Test AdUnitId => “testb4znbuh3n2”

IronSource Huawei Custom Adapter Edit

After adding our ads, we need to turn off the test ads belonging to IronSource in order to test Huawei ads.

Turn off IronSource Test Use

We close the test ads as in the images below.

Turn off IronSource Test Use

After adding Huawei ads and turning off IronSource test ads, we see a screen like the image below in the panel.

IronSource Active and Passive Mediation

Huawei Ads Unity Editor Settings and Demo Scene Test

In order for our Huawei ads to work in our Unity project and anroid projects, we need to make some changes in gradle files.

In order for these files to be active, we edit the area under Project Settings > Player > Android > Publish Settings > Build from the build settings as in the image below left.

Then, in the images below, there are file names and settings to be added into it. We add them. ✍️

Customizing Gradle Files
Customizing Gradle Files

⚠️Do not forget to match the Package Name field from Unity build settings with the package name field of your application in Huawei AppGallery Connect.

Now that we have taken care of our settings, we can test our application by taking the build. 📲

Build

In the images below we see a demo of the use of Huawei ads on IronSource.

Displaying Huawei Ads via IronSource

Inserting Huawei Ads into the Game Scene Using IronSource

Now it’s time to create our own script and scene in our project.

The codes you see in the code block below are basically written for Rewarded Ad and Interstital Ad to work. It will be enough to enter your own APP_KEY in the APP_KEY field and run it.

If you want to get the details of the codes, you can go to the IronSource Developer site and review them there.

After adding our code to our project, we prepare a simple screen as in the image below. The structure here is completely up to you. The structure here is prepared only for a simple display.

Advertising Screen Design

After adding our code and screen to our project, we can now build and run our game. In the images below you can see a simple and working version of the advertising system in the game.

Ad Tests

Here we see 2 ads. For Rewarded Ad, if we watch it successfully, the Score field increases by 1 point. Interstital Ad, on the other hand, must first be loaded by loading and then the ad can be watched with Show.

Ad Tests

Conclusion

Well folks, we’ve made it to the finish line of yet another marathon guide. Step by step and in detail, we have implemented together how Huawei ads are added as mediation using Unity LevelPlay — IronSource. Thank you for reading this far. Thanks to the steps you have applied, you can now show Huawei ads in your game and earn profit 💰💲

Finally, if you want to reach the project in this article, I leave the link here.

Thank you very much for reading 👏. I hope it was useful for you. And as always, it has been a pleasure to guide you through this journey. Until next time, stay healthy and happy gaming!👋🤗.

Congratulations

“Success is not final, failure is not fatal: it is the courage to continue that counts.” — Winston Churchill

--

Seyyid Yiğit
Huawei Developers

I’m a software engineer at Huawei. I love AI, fitness, gaming and sharing my projects and tips with you. Curious? Let’s learn together!