How to conditionally bypass AdMob Mediation and initialize Unity Ads directly on Huawei devices (No GMS)?


I have an Android app that uses AdMob Mediation as the primary ad network, with Unity Ads as a mediation partner. This works perfectly on standard Android devices.

However, I am now compiling a build for the Huawei AppGallery. Since modern Huawei devices lack Google Mobile Services (GMS), the Google AdMob SDK crashes or fails to initialize. Because AdMob acts as the mediation gatekeeper, the ad request dies before it ever reaches Unity Ads.

How can I safely check for GMS at runtime in Kotlin, initialize AdMob if it's a standard Android phone, but completely bypass AdMob and initialize the Unity Ads SDK directly if it is a Huawei (HMS) device?

0
Jun 24 at 6:48 PM
User AvatarMD Mohseen
#android#unity-game-engine#huawei-mobile-services

Accepted Answer

To solve this, you must stop relying on AdMob Mediation for your Huawei users and instead implement a GMS Gateway Check at launch.

Since the Unity Ads SDK does not strictly require Google Play Services to function, it will run perfectly on an HMS device if you call it directly.

Here is the Kotlin implementation using GoogleApiAvailability to detect the device environment and route the initialization accordingly.

1. The Gateway Logic (in your Activity):

Kotlin

import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import com.unity3d.ads.UnityAds
import com.google.android.gms.ads.MobileAds

// Set a flag to track which network you are using
private var isUsingUnityAds = false 

val gmsStatus = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this)

if (gmsStatus == ConnectionResult.SUCCESS) {
    isUsingUnityAds = false
    // GMS is present (Standard Android): Initialize AdMob Mediation
    MobileAds.initialize(this) {
        // Load AdMob banners and interstitials here
    }
} else {
    isUsingUnityAds = true
    // GMS is missing (Huawei): Bypass AdMob entirely and initialize Unity Ads
    val unityGameID = "YOUR_UNITY_GAME_ID"
    UnityAds.initialize(applicationContext, unityGameID, false, this)
}
User AvatarMD Mohseen
Jun 24 at 6:50 PM
0