I am brand-new to Cordova and mobile app development. I am following the instructions for the plugin admob-plus-cordova, to show a BANNER AD, here:
The deviceready async event listener is firing, and all code before await admob.start()
runs successfully, but not the console.log('AdMob started.')
. I have done all I could see in the documentation, but admon-start() does not complete in order to do show the ad.
Additional information
- The plugin is added successfully.
- No errors in my console when emulating Android. Build is successful.
- My Ad Unit is set up correctly, however, I am testing first, thus using the Google Test ad ca-pub-xxx/yyy.
- My Application ID is correctly configured in AndroidManifest (the plugin does this for me).
- My app build.gradle file implements the play-services-ads:20.3.0 (the plugin also does this for me).
mavenCentral()
andgoogle()
are loaded in my repositories.gradle file (the plugin also does this).- Upon @Eric's comment below, I added a catch to the
await.admob.start()
promise. It does not execute the catch either - no output in the console when doing conbsole.log(e).
AndroidManifest.xml
<activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:excludeFromRecents="true" android:name="com.google.android.gms.ads.AdActivity" android:noHistory="true" />
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-mypublisher~informationhere" />
<meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT" android:value="true" />
index.js
let banner
document.addEventListener('deviceready', async () => {
console.log('Running cordova-' cordova.platformId '@' cordova.version '. Starting AdMob');
document.getElementById('deviceready').classList.add('ready');
await admob.start().then(() => {
console.log('AdMob started.');
}).catch(e => console.log(e));
banner = new admob.BannerAd({
adUnitId: 'ca-app-pub-3940256099942544/6300978111', // THIS IS A GOOGLE TEST AD
position: 'top'
})
banner.config({
marginTop: 10,
marginBottom: 5,
backgroundColor: 'black'
})
banner.on('impression', async (evt) => {
await banner.hide()
})
await banner.show()
console.log('Showing ad.')
}, false)
I can't help but think that I need to create a container for my app within my HTML file, but I am not finding anything indicating this while doing a Google search. As it stands, I am expecting to see "AdMob started." after the call the admob.start()
.
Any ideas?
CodePudding user response:
A friend offline of Stack Overflow showed me about chrome://inspect (apparently, it is not the same as the normal inspector when working with Cordova - I do not know why). It showed me an error which is not present in the normal code inspector. After resolving that error, the issue was resolved.