adMob with dedicated test ad unit ID in onAdFailedToLoad return Invalid template ID: -1

25 Views Asked by At

I'm trying to load test native ads to display on emulator. I use the identifier specified in the manual - dedicated test ad unit ID for native ads:

ca-app-pub-3940256099942544/2247696110

but I got in onAdFailedToLoad (adError.message) message:

Invalid template ID: -1

and no results in forNativeAd method.

Internal data in adError response :

{
  "Response ID": "CNbp1fi67IQDFa5UkQUdEswEeA",
  "Mediation Adapter Class Name": "",
  "Adapter Responses": [
    {
      "Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
      "Latency": 184,
      "Ad Source Name": "Reservation campaign",
      "Ad Source ID": "7068401028668408324",
      "Ad Source Instance Name": "[DevRel] [DO NOT EDIT] Native Ads Campaign",
      "Ad Source Instance ID": "3518433842871043",
      "Credentials": {},
      "Ad Error": "null"
    }
  ],
  "Loaded Adapter Response": {
    "Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
    "Latency": 184,
    "Ad Source Name": "Reservation campaign",
    "Ad Source ID": "7068401028668408324",
    "Ad Source Instance Name": "[DevRel] [DO NOT EDIT] Native Ads Campaign",
    "Ad Source Instance ID": "3518433842871043",
    "Credentials": {},
    "Ad Error": "null"
  },
  "Response Extras": {
    "mediation_group_name": "Campaign"
  }
}

My code:

MobileAds.initialize(this) {
            adLoader = AdLoader.Builder(this, "ca-app-pub-3940256099942544/2247696110") // test ad unit ID for native ads
                .forNativeAd { nativeAd: NativeAd ->
                    if (isDestroyed) {
                        nativeAd.destroy()
                        return@forNativeAd
                    }
                    Log.i("NativeAd received $nativeAd")
                }
                .withAdListener(object : AdListener() {
                    override fun onAdFailedToLoad(adError: LoadAdError) {
                       Log.e(adError.message)
                    }
                })
                .withNativeAdOptions(
                    NativeAdOptions.Builder().build()
                )
                .build()
        }

build.gradle.kts

...
    implementation("com.google.android.gms:play-services-ads:23.0.0")
...

In LogCat I did find message:

I/Ads: Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified

Please tell me what needs to be fixed so that the advertisement loads.

1

There are 1 best solutions below

0
LordTAO On

I changed the ID to my real one. Everything worked. AdMob detects my emulator as a test device automatically. Therefore, though I test the app with my real ad ID, anyway I got test NativeAd data. These ads contain Test Ad notes. So, perhaps we don't need to use a dedicated test ad unit ID and things will work.