Admob Installation

This forum contains topics that were moved from Get Satisfaction
Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Hello Support
I am trying to install admob on my app. The followed Illya Stepanov 7 steps instructions on the post https://getsatisfaction.com/apperyio/... However when I build the apk file I receive the following failure

Build error

Most likely build error cause:

:compileReleaseJava/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:8: error: cannot find symbol
import org.apache.cordova.LinearLayoutSoftKeyboardDetect;
^
symbol: class LinearLayoutSoftKeyboardDetect
location: package org.apache.cordova
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:15: error: package com.google.ads does not exist
import com.google.ads.Ad;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:16: error: package com.google.ads does not exist
import com.google.ads.AdListener;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:17: error: package com.google.ads does not exist
import com.google.ads.AdRequest;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:18: error: package com.google.ads.AdRequest does not exist
import com.google.ads.AdRequest.ErrorCode;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:19: error: package com.google.ads does not exist
import com.google.ads.AdSize;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:20: error: package com.google.ads.doubleclick does not exist
import com.google.ads.doubleclick.DfpAdView;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:21: error: package com.google.ads.doubleclick does not exist
import com.google.ads.doubleclick.DfpInterstitialAd;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:22: error: package com.google.ads.mediation.admob does not exist
import com.google.ads.mediation.admob.AdMobAdapterExtras;
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:31: error: cannot find symbol
private DfpAdView adView;
^
symbol: class DfpAdView
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:32: error: cannot find symbol
private DfpInterstitialAd intertitial;
^
symbol: class DfpInterstitialAd
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:120: error: cannot find symbol
final AdSize adSize, final CallbackContext callbackContext) {
^
symbol: class AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:429: error: cannot find symbol
public static AdSize adSizeFromSize(String size) {
^
symbol: class AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:379: error: cannot find symbol
private class BannerListener implements AdListener {
^
symbol: class AdListener
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:382: error: cannot find symbol
public void onReceiveAd(Ad ad) {
^
symbol: class Ad
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:390: error: cannot find symbol
public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
^
symbol: class Ad
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:390: error: cannot find symbol
public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
^
symbol: class ErrorCode
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:397: error: cannot find symbol
public void onPresentScreen(Ad ad) {
^
symbol: class Ad
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:402: error: cannot find symbol
public void onDismissScreen(Ad ad) {
^
symbol: class Ad
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:407: error: cannot find symbol
public void onLeaveApplication(Ad ad) {
^
symbol: class Ad
location: class AdMobPlugin.BannerListener
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:115: error: cannot find symbol
AdSize adSize = adSizeFromSize(size);
^
symbol: class AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:135: error: cannot find symbol
adView = new DfpAdView(cordova.getActivity(), adSize,
^
symbol: class DfpAdView
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:138: error: cannot find symbol
LinearLayoutSoftKeyboardDetect parentView = (LinearLayoutSoftKeyboardDetect) webView
^
symbol: class LinearLayoutSoftKeyboardDetect
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:138: error: cannot find symbol
LinearLayoutSoftKeyboardDetect parentView = (LinearLayoutSoftKeyboardDetect) webView
^
symbol: class LinearLayoutSoftKeyboardDetect
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:139: error: cannot find symbol
.getParent();
^
symbol: method getParent()
location: variable webView of type CordovaWebView
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:187: error: cannot find symbol
intertitial = new DfpInterstitialAd(cordova.getActivity(), publisherId);
^
symbol: class DfpInterstitialAd
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:252: error: cannot find symbol
AdRequest request = new AdRequest();
^
symbol: class AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:252: error: cannot find symbol
AdRequest request = new AdRequest();
^
symbol: class AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:264: error: cannot find symbol
request.addTestDevice(AdRequest.TEST_EMULATOR);
^
symbol: variable AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:266: error: cannot find symbol
AdMobAdapterExtras extras = new AdMobAdapterExtras();
^
symbol: class AdMobAdapterExtras
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:266: error: cannot find symbol
AdMobAdapterExtras extras = new AdMobAdapterExtras();
^
symbol: class AdMobAdapterExtras
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:306: error: cannot find symbol
AdRequest request = new AdRequest();
^
symbol: class AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:306: error: cannot find symbol
AdRequest request = new AdRequest();
^
symbol: class AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:318: error: cannot find symbol
request.addTestDevice(AdRequest.TEST_EMULATOR);
^
symbol: variable AdRequest
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:320: error: cannot find symbol
AdMobAdapterExtras extras = new AdMobAdapterExtras();
^
symbol: class AdMobAdapterExtras
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:320: error: cannot find symbol
AdMobAdapterExtras extras = new AdMobAdapterExtras();
^
symbol: class AdMobAdapterExtras
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:355: error: cannot find symbol
LinearLayoutSoftKeyboardDetect parentView = (LinearLayoutSoftKeyboardDetect) webView
^
symbol: class LinearLayoutSoftKeyboardDetect
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:355: error: cannot find symbol
LinearLayoutSoftKeyboardDetect parentView = (LinearLayoutSoftKeyboardDetect) webView
^
symbol: class LinearLayoutSoftKeyboardDetect
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:356: error: cannot find symbol
.getParent();
^
symbol: method getParent()
location: variable webView of type CordovaWebView
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:381: error: method does not override or implement a method from a supertype
@Override
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:389: error: method does not override or implement a method from a supertype
@Override
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:396: error: method does not override or implement a method from a supertype
@Override
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:401: error: method does not override or implement a method from a supertype
@Override
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:406: error: method does not override or implement a method from a supertype
@Override
^
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:431: error: cannot find symbol
return AdSize.BANNER;
^
symbol: variable AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:433: error: cannot find symbol
return AdSize.IAB_MRECT;
^
symbol: variable AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:435: error: cannot find symbol
return AdSize.IAB_BANNER;
^
symbol: variable AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:437: error: cannot find symbol
return AdSize.IAB_LEADERBOARD;
^
symbol: variable AdSize
location: class AdMobPlugin
/srv/tiggzi/jenkins/workspace/346201-android/178327/346201/android/Test/src/com/google/cordova/plugin/AdMobPlugin.java:439: error: cannot find symbol
return AdSize.SMART_BANNER;
^
symbol: variable AdSize
location: class AdMobPlugin
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
49 errors
FAILED

FAILURE: Build failed with an exception.

How can I resolve this?

Mark

Serhii Kulibaba
Posts: 136
Joined: Tue Aug 27, 2013 1:47 pm

Admob Installation

Post by Serhii Kulibaba »

Hello Mark,

It is better to use cordova plugins for that. e.g.:
https://github.com/floatinghotpot/cor...
https://github.com/floatinghotpot/cor...

Please delete edited (blue colored) files on Source tab and click Undo all source changes on folder with edited files.

And install any admob plugin to your application: https://devcenter.appery.io/documenta...

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Hello Support
Thank you for your reply. I have undone the changes and imported the plugin as you instructed. Also I added the following to my Javascript file.

var admobid = {};

//alert(navigator.userAgent);

// select the right Ad Id according to platform
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-xxx',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
alert ("andriod");
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-xxx',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
alert ("ios");
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-xxx',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
alert ("WP");
}

window.admob.createBannerView(
{
'publisherId': 'xxx',
'adSize': admob.AD_SIZE.BANNER
},
successCallback,
failureCallback
);

window.admob.requestAd(
{
'isTesting': false,
'extras': {
'color_bg': 'AAAAFF',
'color_bg_top': 'FFFFFF',
'color_border': 'FFFFFF',
'color_link': '000080',
'color_text': '808080',
'color_url': '008000'
},
},
successCallback,
failureCallback
);

function initApp() {
if (AdMob) {
AdMob.createBanner({
adId : admobid.banner,
position : AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow : true
});
}
}

var successCreateBannerView = function() { alert("addBanner Success");

window.admob.requestAd({'isTesting': true},success,error); };

var success = function() { alert("requestAd Success"); };

var error = function(message) { alert("Oopsie! " + message); };

var options = {
'publisherId': 'xxx',
'adSize': 'BANNER'
};
function initApp() {
window.admob.createBannerView(options,successCreateBannerView,error);

}

document.addEventListener('deviceready', initApp, false);

Then on device I have the following javascript

function initApp()

I exported the apk file onto a real device but no ads are displayed. How can I fix this?

Mark

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Update:
I have through the docs and it says that I only need to add the following code to your project to activate the ads

var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
}

if(( /(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent) )) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp();
}

function initApp() {
if(AdMob) AdMob.createBanner( {
adId: admobid.banner,
position: AdMob.AD_POSITION.TOP_CENTER,
autoShow: true } );
}

I added the above code to my javascript file and exported to a device however no ads are displayed. When I run the appery web test I see the following error

Uncaught ReferenceError: AdMob is not defined

which is referring to the line "if(AdMob) AdMob.createBanner( {"

It seems that javascript cannot execute the imported pluggin

can you help?

Mark

Serhii Kulibaba
Posts: 136
Joined: Tue Aug 27, 2013 1:47 pm

Admob Installation

Post by Serhii Kulibaba »

Could you add JS file with AdMob object as a custom JS (Create new-JavaScript)

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

Ok I figured it out. To help those who wish to add admob to their app without exporting to eclipse etc, here are the steps to follow:~

1. import the plugin from github https://github.com/floatinghotpot/cor... to appery as explained here https://devcenter.appery.io/documenta...

2.Create new-JavaScript (or open your existing one)

3. add the following code to the file

// place our admob ad unit id here
var admobid = {};
if( /(android)/i.test(navigator.userAgent) ) {
admobid = { // for Android
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
};
} else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
admobid = { // for iOS
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
};
} else {
admobid = { // for Windows Phone
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
};
}

function onDeviceReady() {
if (! AdMob) { alert( 'admob plugin not ready' ); return; }

initAd();

// display a banner at startup
createSelectedBanner();
}

function initAd(){
AdMob.setOptions({
// adSize: 'SMART_BANNER',
// width: integer, // valid when set adSize 'CUSTOM'
// height: integer, // valid when set adSize 'CUSTOM'
position: AdMob.AD_POSITION.BOTTOM_CENTER,

// offsetTopBar: false, // avoid overlapped by status bar, for iOS7+
bgColor: 'black', // color name, or '#RRGGBB'
// x: integer, // valid when set position to 0 / POS_XY
// y: integer, // valid when set position to 0 / POS_XY
isTesting: true, // set to true, to receiving test ad for testing purpose
// autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
});

// new events, with variable to differentiate: adNetwork, adType, adEvent
$(document).on('onAdFailLoad', function(data){
alert('error: ' + data.error +
', reason: ' + data.reason +
', adNetwork:' + data.adNetwork +
', adType:' + data.adType +
', adEvent:' + data.adEvent); // adType: 'banner', 'interstitial', etc.
});
$(document).on('onAdLoaded', function(data){});
$(document).on('onAdPresent', function(data){});
$(document).on('onAdLeaveApp', function(data){});
$(document).on('onAdDismiss', function(data){});

function createSelectedBanner(){
AdMob.createBanner({
adId: admobid.banner,
overlap: $('#overlap').is(':checked'),
offsetTopBar: $('#offsetTopBar').is(':checked'),
adSize: $('#adSize').val(),
position: $('#adPosition').val(),
});
}

function showBannerAtPosition(){
AdMob.showBanner( $('#adPosition').val() );
}

$('#btn_create').click(createSelectedBanner);
$('#btn_remove').click(function(){
AdMob.removeBanner();
});

$('#btn_show').click(showBannerAtPosition);
$('#btn_hide').click(function(){
AdMob.hideBanner();
});

// create a banner on startup
createSelectedBanner();

// test interstitial ad
$('#btn_prepare').click(function(){
AdMob.prepareInterstitial({
adId:admobid.interstitial,
autoShow: $('#autoshow').is(':checked'),
});
});

$('#btn_showfull').click(function(){
AdMob.showInterstitial();
});

// test case for #256, https://github.com/floatinghotpot/cor...
$(document).on('backbutton', function(){
if(window.confirm('Are you sure to quit?')) navigator.app.exitApp();
});

// test case #283, https://github.com/floatinghotpot/cor...
$(document).on('resume', function(){
AdMob.showInterstitial();
});
}

// test the webview resized properly
$(window).resize(function(){
$('#textinfo').html('web view: ' + $(window).width() + " x " + $(window).height());
});

$(document).ready(function(){
// on mobile device, we must wait the 'deviceready' event fired by cordova
if(/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent)) {
document.addEventListener('deviceready', onDeviceReady, false);
} else {
onDeviceReady();
}
});

4.Export project to a real device and your should see the test ads displayed

5. You can then change the banner ID to your own and tweak any other settings

Regards,

Mark

asid
Posts: 0
Joined: Sun Aug 09, 2015 8:01 pm

Admob Installation

Post by asid »

Thanks for sharing

Miguel Angel Dulcey Diaz
Posts: 0
Joined: Tue Aug 27, 2013 3:31 am

Admob Installation

Post by Miguel Angel Dulcey Diaz »

Hi,

How do I invoke the plugin?

Sorry for the newbie

MIGUEL

Mark7294305
Posts: 0
Joined: Fri Dec 26, 2014 2:10 am

Admob Installation

Post by Mark7294305 »

on your home page create an event on device ready to run a script and add the following code

window.admob.createBannerView (
{
'PublisherID': 'ca-app-pub-*****',
'AdSize': admob.AD_SIZE.BANNER
},
successCallback,
failureCallback
);

admob.requestAd(
{
'isTesting': false,
'extras': {
'color_bg': 'AAAAFF',
'color_bg_top': 'FFFFFF',
'color_border': 'FFFFFF',
'color_link': '000080',
'color_text': '808080',
'color_url': '008000'
},
},
successCallback,
failureCallback
);

Let me know if it works

Miguel Angel Dulcey Diaz
Posts: 0
Joined: Tue Aug 27, 2013 3:31 am

Admob Installation

Post by Miguel Angel Dulcey Diaz »

Mark, Thanks for your answer.

I can not make it work.

Blocking the application. It stays charged.

Post Reply