AdMobFree banner not showing after ionic cordova build android –prod –release

AdMobFree banner not showing after ionic cordova build android –prod –release. AdMob top banner not working after ionic android –prod or –release build. Ionic AdMob banner not showing solution with example.

Ionic cordova normal build or run android not showing proper AdMobFree banner, but after generating –prod –release build top banner not display. Mostly when banner autoShow code exist in any page or banner display event initiate in page constructor, banner not showing with release build.

AdMobFree banner not showing after ionic cordova build android --prod --release
AdMobFree banner not showing after ionic cordova build android –prod –release

For above Ionic Native – AdMob Free banner not showing issue, here are steps to display AdMob banner with ionic –prod or ionic –release build.

Solution steps: AdMobFree banner not showing – Ionic –prod –release build

  • Remove AdMobFree banner code from page
  • Add AdMob banner code in app.component.ts
  • import AdMobFree and set in constructor
  • Create show AdMob banner function
  • Call AdMob banner display function from constructor

Remove AdMobFree banner code from page

If load AdMob top banner code added in any page with autoShow or initiate in constructor, need to remove from page.

Add AdMob banner code in app.component.ts

AdMob banner code works proper in app.component.ts. need to add code in file.

import AdMobFree and set object in constructor

import AdMobFree and set object admobFree variable using AdMobFree class in app.component.ts MyApp constructor.

//import AdMobFree
import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';

//Set object in constructor
export class MyApp {
  ...

  constructor(..., private admobFree : AdMobFree) {
  ...
  ...
}

Create show AdMob banner function

Add new function for show banner in app.component.ts and call it from constructor. below is sample code for it.

//Call show banner from constructor
export class MyApp {
    ...
  
    constructor(..., private admobFree : AdMobFree) {
        platform.ready().then(() => {
            ...
            this.showAdmobBannerAds();
        });
    }
  
    //Add function 
    showAdmobBannerAds(){
        const bannerConfig: AdMobFreeBannerConfig = {
        id: 'ID-OF-AD-UNIT',
            isTesting: false,
            autoShow: true,
            bannerAtTop: true
        };
        this.admobFree.banner.config(bannerConfig);

        this.admobFree.banner.prepare()
        .then(() => {})
        .catch(e => console.log(e));    
    }
}