Closed hakanu closed 7 years ago
Can you share your project?
Here is the relevant piece of my project:
`var admob = require("nativescript-admob");
exports.loaded = function(args) { page = args.object; page.bindingContext = pageData; googleAnalytics.logView("tabs"); pageData.city = cache.get(config._CACHE_KEY_CITY); pageData.country = cache.get(config._CACHE_KEY_COUNTRY); createAdmobAd(); };
function createAdmobAd() { admob.createBanner({ // if this 'view' property is not set, the banner is overlayed on the current top most view // view: .., testing: true, // set to false to get actual banners size: admob.AD_SIZE.SMART_BANNER, // anything in admob.AD_SIZE iosBannerId: "ca-app-pub-9517346003011652/3985369721", // add your own androidBannerId: "ca-app-pub-9517346003011652/7749101329", // add your own // Android automatically adds the connected device as test device with testing:true, iOS does not iosTestDeviceIds: ["yourTestDeviceUDIDs", "canBeAddedHere"], margins: { // if both are set, top wins //top: 10 bottom: 50 } }).then( function() { console.log("admob createBanner done"); }, function(error) { console.log("admob createBanner error: " + error); } ); } `
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="loaded">
... and some tabView
I can not really find a big difference between demo and my project. I guess only difference is that you have an additional level of abstraction main-page.js and main-view-model.js. Do you think that kind of structure would solve my problem?
Thanks.
friendly ping?
If you're on plugin version 1.1.4 or higher you should be able to load an ad from the loaded
event, so that's ok.
Just sounds like the native libraries are missing. Can you remove and add the android folder and update your Android libraries (by running android
in a terminal)?
And if you need anything else: post the project (not small bits) so I can easily reproduce the error.
Had the same error but a little different as I am using Angular 2
JS: Error in admob.createBanner: TypeError: com.google.android.gms.ads.AdView is not a function JS: admob createBanner error: TypeError: com.google.android.gms.ads.AdView is not a Constructor
I had this happen to me for a while.
Turns out that running livesync
right after adding AdMob gives this error.
What I did was:
After adding AdMob plugin and the relevant code to the project, I build and installed the project using tns run andorid
That showed the ad.
After which running livesynce
gives no errors.
@hakanu Can you build the project again. Have seen a lot of issues go away doing so. If that does not work try removing and adding the platform again then building your app.
Hello, noobie in NativeScript here. Just to save some time to someone else who stumbles upon the same topic.
Running in the terminal the following commands solved the issue for me:
tns platform remove android
tns platform add android
(it's the advice of Eddy from above. with more detail)
Building the app first for safety
tns build android
and then
tns run android
for livesync.
Another note, if you are trying to create a banner on loaded trying using setTimeout for calling the createBanner to avoid issues.
var loaded = function()
{
setTimeout(function() {
admob.createBanner({ ..... });
}, 1000);
}
I know these steps may seems obvious to most people after reading the advices above, but they may help save time to a novice in NativeScript like me. Cheers.
Hi,
Sorry, me again. I'm still trying to make this work. I can successfully build and run the demo admob app and I can see the ad but in my app I guess I'm missing something. I keep getting this error:
JS: Error in admob.createBanner: TypeError: com.google.android.gms.ads.AdView is not a function JS: admob createBanner error: TypeError: com.google.android.gms.ads.AdView is not a function
Any idea is welcome.