Skip to content

Explore-In-HMS/huawei.ads.admob_mediation

Repository files navigation

Huawei-Admob Mediation Github Documentation

latest_version_for_above_20.6.0 latest_version_for_below_20.5.0
Kotlin
Supported Platforms

Introduction

In this documentation we explained how to use Huawei-Admob mediation with in the different platforms.

Compatibility

Banner Ad Interstitial Ad Rewarded Ad Native Ad
Native (Java/Kotlin)
Unity
React Native
Flutter
Cordova

How to start?

Create an ad unit on Huawei Publisher Service

  1. Sign in to Huawei Developer Console and create an AdUnit

Create a custom event on Google AdMob

Make sure to check the article on How to use Huawei Ads with AdMob mediation ?

  1. Sign in to Google AdMob console
  2. Go to "Mediation -> Create a new Mediation Group" (or, use one of the existing Mediation groups)
  3. Under the "Ad Sources" section, click "Add Custom Event" Give it a label (eg: Huawei Banner Custom Event) and an eCPM, click "Continue"
  4. Enter the class name "com.hmscl.huawei.admob_mediation.all_ads" as the Class Name, and your Huawei's AdUnit ID from step 1 as the parameter
  5. Add the adapter and its dependencies into your project
  6. Configuration of custom event is done.

Create a custom event on Google Ad Manager

Make sure to check the article on How to Use Huawei Ads with Google Ad Manager ?

  1. Sign in to Google Ad Manager console
  2. Add Huawei as a Ad Network Company by selecting Other company in Ad Network section
  3. Go to "Delivery -> Yield groups" (or, use one of the existing groups)
  4. Create a yield group and add Huawei as a yield partner
  5. Enter the class name "com.hmscl.huawei.admob_mediation.all_ads" as the Class Name, and your Huawei's AdUnit ID from step 1 as the parameter
  6. Add the adapter and its dependencies into your project
  7. Configuration of custom event is done.

Integrate the Huawei Mediation SDK

In the project-level build.gradle, 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
    }
}

In the app-level build.gradle, include Huawei Ads and Google AdMob SDK dependencies (required by the adapter) and the adapter, Google Consent SDK is optional.
dependencies {
    //Huawei Ads Prime
    implementation 'com.huawei.hms:ads-prime:<latest_version>'
    //Google AdMob SDK
    implementation 'com.google.android.gms:play-services-ads:<latest_version>'
    //Optional: Google Consent SDK
    implementation "com.google.android.ads.consent:consent-library:<latest_version>"
}

NOTE: If your app can run only on Huawei mobile phones, you can integrate the Huawei Ads Lite SDK instead of Huawei Ads SDK (Optional)

dependencies {
    ...
    //Huawei Ads Lite
    implementation 'com.huawei.hms:ads-lite:<latest_version>'
    ...
}

NOTE: To implement Huawei Ads Admob mediation adapter :

dependencies {
    ...
    //If your app uses Google Admob SDK 20.6.0 and above versions, use :
    implementation 'com.github.Explore-In-HMS:huawei.ads.admob_mediation:<latest_version_for_above_20.6.0>'
    ...

    //If your app uses Google Admob SDK 20.5.0 and below version, use :
    implementation 'com.github.Explore-In-HMS:huawei.ads.admob_mediation:<latest_version_for_below_20.5.0>'
}

Latest version of SDKs

Important: To add Huawei Ads Kit SDK and Mediation adapter, the native project should be opened with Android Studio.

Permissions

The HUAWEI Ads SDK (com.huawei.hms:ads) has integrated the required permissions. Therefore, you do not need to apply for these permissions.

android.permission.ACCESS_NETWORK_STATE: Checks whether the current network is available.

android.permission.ACCESS_WIFI_STATE: Obtains the current Wi-Fi connection status and the information about WLAN hotspots.

android.permission.BLUETOOTH: Obtains the statuses of paired Bluetooth devices. (The permission can be removed if not necessary.)

android.permission.CAMERA: Displays AR ads in the Camera app. (The permission can be removed if not necessary.)

android.permission.READ_CALENDAR: Reads calendar events and their subscription statuses. (The permission can be removed if not necessary.)

android.permission.WRITE_CALENDAR: Creates a calendar event when a user clicks the subscription button in an ad. (The permission can be removed if not necessary.)

Configuring Obfuscation Scripts

Before building the APK, configure the obfuscation configuration file to prevent the HUAWEI Ads SDK () from being obfuscated.

Open the obfuscation configuration file proguard-rules.pro in the app-level directory of your Android project, and add configurations to exclude the HUAWEI Ads SDK from obfuscation.

-keep class com.huawei.openalliance.ad.** { *; }
-keep class com.huawei.hms.ads.** { *; }

Configuring Network Permissions

To allow HTTP and HTTPS network requests on devices with targetSdkVersion 28 or later, configure the following information in the AndroidManifest.xml file:

<application
    ...
    android:usesCleartextTraffic="true"
    >
    ...
</application>

Version Change History

2.0.2

New Smart Banner & Advanced Banner type support added. Oversized banner issue is fixed

2.0.0

Library updated to support Admob's new mediation classes.

1.2.9

Update Huawei Ads SDK. Resolved the compatibility issue of the network component OkHttp.

1.2.8

Minor fixes.

1.2.7

Logs issue fixed.

1.2.6

Logging structure updated, code infrastructure optimized.

1.2.5

Bug fix.

1.2.4

AdListener methods has been added.

1.2.3

OnLoaded() methods has been added .

1.2.2

Ads version updated and Zip Path Traversal issue is fixed.

1.2.1

Min SDK updated.

1.2.0

Transparency & Consent Framework v2.0 and personalized & non-personalized ads configurations are integrated.

Supported Networks through Admob Mediation

IronSource through Admob Mediation

IronSource Ad Network Compatibility

Banner Ad Interstitial Ad Rewarded Ad Native Ad
Native (Java/Kotlin)
Unity

If you want to integrate Ironsource network through Admob mediation follow these steps.

  1. Add Admob for mediation at IronSource SDK Networks.
  2. Enter your App ID and Ad Unit ID from Admob.
  3. Add IronSource admob adapter and gms play services dependency to the project.

Scenario 1: If Publisher has IronSource mediation with Admob

If you have IronSource mediation with Admob you just need to integrate the Huawei admob mediation adapter and make the necessary changes we mentioned on the Admob panel.
Follow here for the integration steps

Scenario 2: If Publisher has only IronSource Ads

If there is only IronSource ads in the application, admob mediation must be done first from the IronSource panel, and then Huawei admob adapter must be added.
For this, admob mediation should be done on IronSource first, and then admob mediation adapter should be added to the project as it was done in the first step.

dependencies {
 implementation 'com.google.android.gms:play-services-ads:20.2.0'
 implementation 'com.ironsource.adapters:admobadapter:4.3.22'
 implementation 'com.huawei.hms:ads:3.4.47.302'
 implementation 'com.github.Explore-In-HMS:huawei.ads.admob_mediation:<latest_version>'
 }

Platforms

Native

This section demonstrates how to use AdMob mediation feature with Huawei Ads Kit on Native android app.

Make sure to check the article on How to use Huawei Ads with AdMob mediation (Native Android)

Firstly, integrate the Admob SDK for Android

Admob Android SDK can be used for all ad types.

Note :

  1. Developers can find app level build.gradle in their project from "app-folder/app/build.gradle"
  2. If you use the native ad format in your application, please submit a ticket here to get support from Huawei.

Banner Ad

To use Banner ads in Native android apps, please check the Admob SDK. Click here to get more information about Admob SDKs Banner Ad development.

Interstitial Ad

To use Interstitial ads in Native android apps, please check the Admob SDK. Click here to get more information about Admob SDKs Interstitial Ad development.

Rewarded Ad

To use Rewarded ads in Native android Rewarded, please check the Admob SDK. Click here to get more information about Admob SDKs Banner Ad development.

Native Ads

To use Native ads in Native android apps, please check the Admob SDK. Click here to get more information about Admob SDKs Native Ad development.

Unity

This section demonstrates how to use Admob mediation feature with Huawei Ads Kit on Unity.

Make sure to check the article on How to use Huawei Ads with Supported Ad Platforms in Unity ?

Supported Ad Formats are: Banner Ads, Interstitial Ads and Rewarded Ads.

Firstly, integrate the Admob Unity SDK to Unity.

For more details on Admob Unity SDK visit here

Banner Ads

To use Banner ads in Unity , please check the Admob Unity SDK. Click here to get more information about Admob Unity SDKs Banner Ad development.

Interstitial Ads

To use Interstitial ads in Unity, please check the Admob Unity SDK. Click here to get more information about Admob Unity SDKs Interstitial Ad development.

Rewarded Ads

To use Rewarded ads in Unity, please check the Admob Unity SDK. Click here to get more information about Admob Unity SDKs Banner Ad development.

Step 1:

Make sure to switch to the Android Platform from Build Settings -> Android -> Switch Platform

Step 2:

Edit -> Project Settings -> Player -> Other Settings
In Other Settings set minimum API level to at least 21.

Step 3:

Edit -> Project Settings -> Player -> Publishing Settings
In Publishing Settings select “Custom Main Gradle Template” , “Custom Base Gradle Template” and “Custom Greadle Properties Template”
This will let you override mainTemplate.gradle , baseProjectTemplate.gradle and gradleTemplate.properties files in the project.

Step 4:

baseProjectTemplate.gradle is equal to project-level gradle so you have to include Huawei's Maven repositories from the Integrate the Huawei Mediation SDK section from here
mainTemplate.gradle is equal to app-level build.gradle so you have to include dependencies from the Integrate the Huawei Mediation SDK section from here.

Step 5:

Open gradleTemplate.properties and add the following lines

android.useAndroidX=true
android.enableJetifier=true

After these configurations is completed you can display Huawei Ads.

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

aaptOptions {
        noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

React Native

This section demonstrates how to use AdMob mediation feature with Huawei Ads Kit on React-Native.

Make sure to check the article on How to use Huawei Ads with AdMob mediation (React Native)

Important: There is no official React Native SDK for Admob therefore third party SDKs has been used in the demonstration.

Firstly, integrate the React Native Admob SDKs as below depending on type of ad

Note: Developers can find app level build.gradle in their project from "app-folder/app/build.gradle"

For Banner , Interstitial and Rewarded Ad type's react-native-admob SDK can be used.

For Native ad type react-native-admob-native-ads SDK can be used.

Then use the following sample codes based on specific ad types.

Sample Codes Based on Ad Types

Banner Ad

<AdMobBanner
adSize="fullBanner"
adUnitId={BannerAdId}
testDevices={[AdMobBanner.simulatorId]}
onAdFailedToLoad={error => console.error(error)} />

Interstitial Ad

AdMobInterstitial.setAdUnitID(InterstitialAdId);
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());

Rewarded Ad

AdMobRewarded.setAdUnitId(RewardedAdId);
AdMobRewarded.requestAd().then(() => AdMobRewarded.showAd());

Native Ads

<NativeAdView
adUnitID= {NativeAdId}
onAdFailedToLoad={error => console.error(error)} />

Flutter

This section demonstrates how to use AdMob mediation feature with Huawei Ads Kit on Flutter.

Make sure to check the article on How to use Huawei Ads with AdMob mediation (Flutter)

Important: There is no official Flutter SDK for AdMob therefore third party SDKs has been used in the demonstration.

Firstly, integrate the Flutter_ AdMob _SDKs as below depending on type of ad

Note: Developers can find app level build.gradle in their project from "app-folder/android/app/build.gradle"

For Banner and Interstitial Ad types admob_flutter SDK can be used.

For Banner and Rewarded Ad types googleads-mobile-flutter SDK can be used.

Native Ad

Native ads are not supported with this SDK. To use Native ads in Flutter app, please check the HMS Core Ads Kit Flutter SDK. Click here to get more information about HMS Core Flutter SDKs Native Ad development.

Then use the following sample codes based on specific ad types.

Sample Codes Based on Ad Types

Banner Ad

Admob.initialize();
…
child: AdmobBanner(
  adUnitId: "Your Banner Ad Unit ID",
  adSize: AdMobBannerSize.[Selected_Banner_Size],
  listener: (AdmobAdEvent event,
      Map<String, dynamic> args) {
    handleEvent(event, args, 'Banner');
  },
  onBannerCreated:
      (AdmobBannerController controller) {
  },
),
…

Interstitial Ad

Admob.initialize();
…
interstitialAd = AdmobInterstitial(
  adUnitId: "Your Intersitatial Ad Unit ID",
  listener: (AdmobAdEvent event, Map<String, dynamic> args) {
    if (event == AdmobAdEvent.closed) interstitialAd.load();
    handleEvent(event, args, 'Interstitial');
  },
);

Rewarded Ad

class RewardedAd extends AdWithoutView {
  ...
  static final String testAdUnitId = Platform.isAndroid
      ? 'Your Rewarded Ad Unit ID'
      : 'Your Rewarded Ad Unit ID';

  @override
  Future<void> load() async {
    await instanceManager.loadRewardedAd(this);
  }
}

Cordova

This section demonstrates how to use AdMob mediation feature with Huawei Ads Kit on Cordova.

Make sure to check the article on How to use Huawei Ads with AdMob mediation (Cordova)

Important: There is no official Cordova SDK for AdMob therefore third party SDKs has been used in the demonstration.

Firstly, integrate the Cordova_ AdMob _SDKs as below depending on type of ad

Note: Developers can find app level build.gradle in their project from "app-folder/platforms/android/app/build.gradle"

For Banner and Interstitial Ad types admob-plus SDK can be used.

Rewarded Ad

Rewarded ads are not supported with this SDK. To use Rewarded ads in Cordova app, please check the HMS Core Ads Kit Cordova SDK. Click here to get more information about HMS Core Cordova SDKs Rewarded Ad development.

Native Ad

Native ads are not supported in Cordova. To use Native Ads in Cordova App please check the HMS Core Ads Kit Cordova SDK. Click here to get more information about HMS Core Cordova SDK Native Ad development.

Then use the following sample codes based on specific ad types.

Sample Codes Based on Ad Types

Banner Ads

showBannerAd() {
  const banner = new admob.BannerAd({
    adUnitId: '[Enter BannerAdID here]',
  })
  return banner.show({ position: 'bottom' })
},

Interstitial Ads

showInterstitialAd() {
  const interstitial = new admob.InterstitialAd({
          adUnitId: '[Enter InterstitialAdID here]',
  })
  return interstitial.load().then(() => interstitial.show())
},

Screenshots

AdMob

Banner Ad

Interstitial Ad

Rewarded Ad

Native Ad

Huawei

Banner Ad

Interstitial Ad

Rewarded Ad

Native Ad