How to use Huawei Ads with AdMob mediation (Flutter)

Gökhan YILMAZ
Huawei Developers
Published in
4 min readMar 9, 2021

--

In this article, we will talk about how to obtain Huawei Ads in AdMob in Flutter applications. Make sure you have successfully completed the Huawei-AdMob mediation creation part before starting the integration.

We will need the AdMob Flutter SDK to integrate AdMob into our app. But there is no official Flutter SDK for AdMob, therefore third party SDKs has been used in the article.

Banner & Interstitial Ads

admob_flutter will be used for integration AdMob into Flutter. You can use another SDK or create your own SDK for integration.

Add AdMob Flutter SDK mentioned above to your project. You can use sample codes in here to make sure integration is okay. After integration run project. Your project should look like this; (You can use test ad IDs to make sure the integration is successful)

Banner & Interstitial Ads (AdMob)
Native & Rewarded Ads (AdMob)

Native Ads will not work on either AdMob or Huawei in this SDK. But with some changes we will solve this problem. We will come to that later.

After you have successfully started the app, you must open the native android project on Android Studio.

Open your project-level gradle file and include Huawei’s maven repository;

repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } // Add this line
maven {url "https://jitpack.io"} // Add this line
}

...

allprojects {
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } //Add this line
maven {url "https://jitpack.io"} // Add this line
}
}

Then open your app-level build gradle, include Huawei Ads dependency (required by the adapter) and the Huawei mediation adapter;

dependencies {
implementation 'com.huawei.hms:ads-lite:13.4.41.302'
implementation 'com.github.Explore-In-HMS:huawei.admob_mediation:<latest_version>'
}

You can find latest_version from GitHub repository.

After successfully adding the Huawei Ads Kit and Huawei mediation adapter to your local project, the remaining steps are very easy.

We used test ad unit IDs at the beginning of the integration. Now replace the ad unit IDs with the ad unit ids after the Huawei-AdMob mediation.

After id changes ads will replace to Huawei Ads.

Banner & Interstitial Ads (Huawei)

Rewarded Ads

google_mobile_ads 0.11.0+2 will be used for integration AdMob into Flutter. You can use another SDK or create your own SDK for integration.

Add AdMob Flutter SDK mentioned above to your project. You can use sample codes in here to make sure integration is okay. After integration run project. Your project should look like this; (You can use test ad IDs to make sure the integration is successful)

Banner & Interstitial Ads (AdMob)
Native & Rewarded Ads (AdMob)

Native Ads and Interstitial Ads will not work on either AdMob or Huawei in this SDK. But with some changes we will solve this problem. We will come to that later.

After you have successfully started the app, you must open the native android project on Android Studio.

Open your project-level gradle file and include Huawei’s maven repository;

repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } // Add this line
maven {url "https://jitpack.io"} // Add this line
}

...

allprojects {
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } //Add this line
maven {url "https://jitpack.io"} // Add this line
}
}

Then open your app-level build gradle, include Huawei Ads dependency (required by the adapter) and the Huawei mediation adapter;

dependencies {
implementation 'com.huawei.hms:ads-lite:13.4.41.302'
implementation 'com.github.Explore-In-HMS:huawei.admob_mediation:<atest_version>'
}

You can find latest_version from GitHub repository.

After successfully adding the Huawei Ads Kit and Huawei mediation adapter to your local project, the remaining steps are very easy.

We used test ad unit IDs at the beginning of the integration. Now replace the ad unit IDs with the ad unit ids after the Huawei-AdMob mediation.

After id changes ads will replace to Huawei Ads.

Banner & Rewarded Ads (Huawei)

Summary

In this article, we learned how to use AdMob-Huawei mediation adapter in Flutter. Even if you use AdMob or other Mobile Ad Networks, you can increase your revenue by using Huawei Ads in your app. Thank you.

References

--

--