https://github.com/floatinghotpot/cordova-plugin-admob
to build. And I even got it to work once! But I messed up something in the plugin.xml and can't find my way back. I've tried all of the docs, but window.plugins.AdMob is always undefined. Any help is greatly appreciated -- I've been at this for days and am about to give up since it builds and installs cleanly with cordova-cli.
52 Answers, 1 is accepted
regards,
Bob Pemberton
The AdMob Cordova plugin is plugman compatible and modified to support Cordova 3.0, so you can download it as a zip from the github repo that Ned posted and add it to your Icenium project as described in our documentation:
Regards,
Steve
Telerik
You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
however, I found a '<js-module src="www/AdMob.js" name="AdMob">'. Should I use that one and modify it to '
=
<asset src="www/AdMob.js" name="AdMob">'?However, I don't get it to work. In the simulator I get a: Uncaught ReferenceError: require is not defined and when building for Android device I get 'package com.google.ads does not exist'.
should I import more than just this plugin? Looks like I am missing the ads package?
However, I don't get it to work. In the simulator I get a: Uncaught ReferenceError: require is not defined and when building for Android device I get 34 errors.
should I import more than just this plugin? Looks like I am missing a something?
1. Clone the plugin down (or add locally with cordova-cli). Zip up the plugin folder and extract to Plugins.
2. Put the IOS sdk files in the src/ios folder.
3. Put the Android sdk jar file in src/android folder
4. Modify plugin.xml and add ...
<source-file src="src/android/GoogleAdMobAdsSdk-6.4.1.jar" target-dir="libs" />
right above the source file for AdMob.js. The clobber needs to be
<js-module src="www/AdMob.js" name="plugins.AdMob">
<clobbers target="plugins.AdMob" />
</js-module>
5. You need to add the line
<plugin name='AdMob' value='com.google.cordova.plugin.admob'/>
6. My javascript looks something like this (I use jquerymobile pageshow event) ...
// is plugin loaded
if (window.plugins.AdMob) {
// vars
var adIdiOS = 'somepubidios';
var adIdAndroid = 'somepubidandroid';
// Might be platform dependant
var adId = (navigator.userAgent.indexOf('Android') >=0) ? adIdAndroid : adIdiOS;
// get new window object
var am = window.plugins.AdMob;
// destroy any running adView
am.destroyBannerView();
// create new adView
am.createBannerView(
{
'publisherId' : adId,
'adSize' : am.AD_SIZE.BANNER,
'bannerAtTop' : false
},
function() {
am.requestAd({
'isTesting' : true,
'extras' : {
'color_bg' : '000000',
'color_bg_top' : '000000',
'color_border' : '000000',
'color_link' : 'FFFFFF',
'color_text' : 'FFFFFF',
'color_url' : 'FFFFFF'
}},
function() {
am.showAd(
true,
function() {},
function() {
console.log('Error showing Ad');
}
);
},
function() {
console.log('Error requesting Ad');
}
);
},
function() {
console.log('Error create Ad Banner');
}
);
} else {
console.log('AdMob plugin not loaded.');
}
8. I would test with "house ads" because the testing flag seems to only work in the Android emulator which is pretty slow and worthless IMO. You will get revenue for impressions if testing is set to true if you are running on actual device!
Hope that helps.
@Ned: thank you for the feedback!
@JD: js-module is the new way to add js references in plugin.xml, the bonus is that you no longer need to add <script> reference to the .js file in your html pages. <asset> would still be used for other kind of resources.
About the plugin - remember that Cordova plugins are not supported in Simulator and ION. You should deploy on actual device.
Regards,
Steve
Telerik
You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
It seems not as easy as I understand from your post. I downloaded the zip archive from the first post of this thread and imported it in my project.
When I build for device I get 34 errors (I wanted to attach a document, but attaching files seems to be broken, please try yourself):
-pre-compile:
-compile:
[javac] Compiling 42 source files to /tmp/b599ad68d1bc489094e7dc0e7428956d/bin/classes
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:3: package com.google.ads does not exist
[javac] import com.google.ads.Ad;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:4: package com.google.ads does not exist
[javac] import com.google.ads.AdListener;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:5: package com.google.ads does not exist
[javac] import com.google.ads.AdRequest;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:6: package com.google.ads.AdRequest does not exist
[javac] import com.google.ads.AdRequest.ErrorCode;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:7: package com.google.ads does not exist
[javac] import com.google.ads.AdSize;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:8: package com.google.ads does not exist
[javac] import com.google.ads.AdView;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:9: package com.google.ads.mediation.admob does not exist
[javac] import com.google.ads.mediation.admob.AdMobAdapterExtras;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:32: cannot find symbol
[javac] symbol : class AdView
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] private AdView adView;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:394: cannot find symbol
[javac] symbol : class AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] public static AdSize adSizeFromSize(String size) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:211: cannot find symbol
[javac] symbol : class AdSize
[javac] location: class org.apache.cordova.plugin.AdMob.CreateBannerViewRunnable
[javac] private AdSize adSize;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:213: cannot find symbol
[javac] symbol : class AdSize
[javac] location: class org.apache.cordova.plugin.AdMob.CreateBannerViewRunnable
[javac] public CreateBannerViewRunnable(String publisherId, AdSize adSize) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:350: cannot find symbol
[javac] symbol : class AdListener
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] private class BannerListener implements AdListener {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:352: cannot find symbol
[javac] symbol : class Ad
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onReceiveAd(Ad ad) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:357: cannot find symbol
[javac] symbol : class Ad
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:357: cannot find symbol
[javac] symbol : class ErrorCode
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:364: cannot find symbol
[javac] symbol : class Ad
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onPresentScreen(Ad ad) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:369: cannot find symbol
[javac] symbol : class Ad
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onDismissScreen(Ad ad) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:374: cannot find symbol
[javac] symbol : class Ad
[javac] location: class org.apache.cordova.plugin.AdMob.BannerListener
[javac] public void onLeaveApplication(Ad ad) {
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:224: cannot find symbol
[javac] symbol : class AdView
[javac] location: class org.apache.cordova.plugin.AdMob.CreateBannerViewRunnable
[javac] adView = new AdView(cordova.getActivity(), adSize, publisherId);
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:279: cannot find symbol
[javac] symbol : class AdRequest
[javac] location: class org.apache.cordova.plugin.AdMob.RequestAdRunnable
[javac] AdRequest request = new AdRequest();
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:279: cannot find symbol
[javac] symbol : class AdRequest
[javac] location: class org.apache.cordova.plugin.AdMob.RequestAdRunnable
[javac] AdRequest request = new AdRequest();
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:285: cannot find symbol
[javac] symbol : variable AdRequest
[javac] location: class org.apache.cordova.plugin.AdMob.RequestAdRunnable
[javac] request.addTestDevice(AdRequest.TEST_EMULATOR);
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:287: cannot find symbol
[javac] symbol : class AdMobAdapterExtras
[javac] location: class org.apache.cordova.plugin.AdMob.RequestAdRunnable
[javac] AdMobAdapterExtras extras = new AdMobAdapterExtras();
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:287: cannot find symbol
[javac] symbol : class AdMobAdapterExtras
[javac] location: class org.apache.cordova.plugin.AdMob.RequestAdRunnable
[javac] AdMobAdapterExtras extras = new AdMobAdapterExtras();
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:351: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:356: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:363: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:368: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:373: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:396: cannot find symbol
[javac] symbol : variable AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] return AdSize.BANNER;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:398: cannot find symbol
[javac] symbol : variable AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] return AdSize.IAB_MRECT;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:400: cannot find symbol
[javac] symbol : variable AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] return AdSize.IAB_BANNER;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:402: cannot find symbol
[javac] symbol : variable AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] return AdSize.IAB_LEADERBOARD;
[javac] ^
[javac] /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/plugin/AdMob.java:404: cannot find symbol
[javac] symbol : variable AdSize
[javac] location: class org.apache.cordova.plugin.AdMob
[javac] return AdSize.SMART_BANNER;
[javac] ^
[javac] Note: /tmp/b599ad68d1bc489094e7dc0e7428956d/src/org/apache/cordova/core/InAppBrowser.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 34 errors
Done building project "tstAdMob.proj" -- FAILED.
Either I am missing something or I should follow all steps Ned explained. I have understood that AdMob is plugman compatible.
http://stackoverflow.com/questions/17311075/after-update-to-xcode-5-ld-symbols-not-found-for-architecture-armv7-or-armv
Is there a way to tweak the build settings in Icenium to allow this to build?
SOLUTION:
This seemed to work in the IOS section of plugins.xml ...
<source-file src="src/ios/libGoogleAdMobAds.a" framework="true" target-dir="libs" compiler-flags="-fno-objc-arc"/>
In Step 5 you explain to add that line to both plugins.xml in docroot and in res/xml/plugins.xml. Unfortunately I can't find those files. Where within the Icenium app do I find those files or where in Icenium would I make both of those edits?
thank you!
The instructions Ned gave are for a Cordova app, while the Icenium project structure differs. You only need to edit one plugin.xml file which is located at the root of the AdMob plugin in the Plugins folder. For more information refer to the following articles from our documentation:
Regards,
Steve
Telerik
You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
I'm too trying to add this plugin to my project, but without any success.
I've already read the whole documentation and it seems the following plugin:
https://github.com/floatinghotpot/cordova-plugin-admob
is compatible out of the box. From the discussion I understand there are no other steps required, other than importing the archive downloaded.
So I'm importing the plugin, deleting any unrelated files like .gitignore, README, etc. Only www and src is left.
The plugin even includes a test folder, so I'm using this as my test code.
I did not want to mess up anything, so I've started with a new blank project.
I've imported the plugin and built for android. Sent the APK to my phone and it's not working.
The test reports AdMob was not loaded.
I have no idea why. I did everything from fresh beginning.
Any clues?
Thanks in advance.
It checks for window.AdMob, where the JS is exported as window.plugins.AdMob.
if( window.plugins.AdMob ) {
var adIdiOS = 'XXXXXXXX';
var adIdAndroid = 'XXXXXXXXX';
var adId = (navigator.userAgent.indexOf('Android') >=0) ? adIdAndroid : adIdiOS;
var am = window.plugins.AdMob;
am.createBannerView(
{
'publisherId' : adId,
'adSize' : am.AD_SIZE.BANNER,
'bannerAtTop' : true
},
window.plugins.AdMob I received the message :TypeError: Cannot read property AdMob or undefined
if I try with:
window.AdMob the plugin is no loaded, so I see the msg AdMob plugin is not loaded.
I import the plugin and follow the instructions.
Please help me!
Regards
Thanks!
I seem to be having some trouble getting this going as well. I'm getting a Server exception Build failed when trying to build for android in Mist. It will build fine for iOS.
These are the steps I followed...
- I started a blank project.
- downloaded the zip file from here https://github.com/floatinghotpot/cordova-plugin-admob
- added the plugin in Mist by right clicking on the Plugins then Import plugin. I selected the zip I downloaded.
- I moved the index.html and the main.js from the Plugins\cordova-plugin-admob-master\test folder to the root
- I edited the main.js file and replaced all instances of window.AdMob with window.plugins.AdMob
- This is where I first tried to build and got the error.
- So, I downloaded the GoogleAdMobAdsSdk-6.4.1.jar and placed it in the cordova-plugin-admob-master\src\android directory
- I edited the plugin.xml and added <source-file src="src/android/GoogleAdMobAdsSdk-6.4.1.jar" target-dir="libs" /> after the engines node
- Tried again to build with no luck.
Does anyone have any ideas to get this to work? Also, is there a log file in Mist that could shed some light on this? Any help would be greatly appreciated.
Thanks!
Josh
- I edited the main.js file and replaced all instances of window.AdMob with window.plugins.AdMob
Below are the steps you have to follow in order to implement the plugin:
- Make a blank project.
- Download and add the plugin in Mist by right clicking on the Plugins then Import plugin. The zip can be found here.
- Add this file android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar to Plugins > cordova-plugin-admob-master >src > android > libs folder.
- Add <source-file src="src/android/libs/google-play-services.jar" target-dir="libs" /> inside <platform name="android"> tag in Plugins > cordova-plugin-admob-master > plugin.xml.
- In the same file as above find and replace the version from this tag <config-file target="AndroidManifest.xml" parent="/manifest/application">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</config-file> to the version from this file on your system android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/res/values/version.xml - If you want to use the test files from Plugins > cordova-plugin-admob-master > test folder edit the main.js file and replace all instances of window.AdMob with window.plugins.AdMob
I hope I haven't missed some of the steps.
Thanks.
Regards,
Zdravko
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET. Seats are limited.
- where do I get the google-play-services.jar file? Please keep in mind I'm a fairly new to all this and confused.
- does the android-sdk need to be added to mist somehow?
Thanks!
https://github.com/MobileChromeApps/google-play-services
I got it to build, but the ad isn't showing. Just a blank space where it should be.
The .jar file is a part of Android SDK and you can find it by following the path in my previous reply after the SDK is installed on your system. You have to add only the .jar file to the indicated position in your app.
For further adjustments to the plugin or Google service please contact respectively plugin's developers or Google support as this is not in the scope of our support service.
Thanks.
Regards,
Zdravko
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
I followed your suggestions and I'm happy to say Android does build now.
The "only" problem is that window.plugins.AdMob == undifined.
I've srearched trough the posts and links suggested in the post but I can't seem to find what I'm doing wrong.
I suspect it has something to do with the plugin.xml so I've added it below.
Help is greatly appreciated.
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
plugin
xmlns
=
"http://apache.org/cordova/ns/plugins/1.0"
xmlns:android
=
"http://schemas.android.com/apk/res/android"
id
=
"com.rjfun.cordova.plugin.admob"
version
=
"1.1"
>
<
name
>AdMob</
name
>
<
description
>Add AdMob support</
description
>
<
author
>Liming Xie</
author
>
<
license
>MIT</
license
>
<
engines
>
<
engine
name
=
"cordova"
version=">=2.9" />
</
engines
>
<
plugin
name
=
'AdMob'
value
=
'com.google.cordova.plugin.admob'
/>
<
js-module
src
=
"www/AdMob.js"
name
=
"AdMob"
>
<
clobbers
target
=
"window.plugins.AdMob"
/>
</
js-module
>
<
source-file
src
=
"src/android/GoogleAdMobAdsSdk-6.4.1.jar"
target-dir
=
"libs"
/>
<!-- android -->
<
platform
name
=
"android"
>
<
source-file
src
=
"src/android/google-play-services.jar"
target-dir
=
"libs"
/>
<
config-file
target
=
"res/xml/config.xml"
parent
=
"/*"
>
<
feature
name
=
"AdMob"
>
<
param
name
=
"android-package"
value
=
"com.rjfun.cordova.plugin.AdMob"
/>
</
feature
>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/manifest/application"
>
<
meta-data
android:name
=
"com.google.android.gms.version"
android:value
=
"4323030"
/>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/manifest/application"
>
<
activity
android:configChanges
=
"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:name
=
"com.google.android.gms.ads.AdActivity"
/>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/*"
>
<
uses-permission
android:name
=
"android.permission.INTERNET"
/>
<
uses-permission
android:name
=
"android.permission.ACCESS_NETWORK_STATE"
/>
</
config-file
>
<
source-file
src
=
"src/android/AdMob.java"
target-dir
=
"src/com/rjfun/cordova/plugin"
/>
</
platform
>
<!-- ios -->
<
platform
name
=
"ios"
>
<
config-file
target
=
"config.xml"
parent
=
"/*"
>
<
feature
name
=
"AdMob"
>
<
param
name
=
"ios-package"
value
=
"CDVAdMob"
/>
</
feature
>
</
config-file
>
<
header-file
src
=
"src/ios/CDVAdMob.h"
/>
<
source-file
src
=
"src/ios/CDVAdMob.m"
/>
<
header-file
src
=
"src/ios/GADAdMobExtras.h"
/>
<
header-file
src
=
"src/ios/GADAdNetworkExtras.h"
/>
<
header-file
src
=
"src/ios/GADAdSize.h"
/>
<
header-file
src
=
"src/ios/GADBannerView.h"
/>
<
header-file
src
=
"src/ios/GADBannerViewDelegate.h"
/>
<
header-file
src
=
"src/ios/GADInterstitial.h"
/>
<
header-file
src
=
"src/ios/GADInterstitialDelegate.h"
/>
<
header-file
src
=
"src/ios/GADRequest.h"
/>
<
header-file
src
=
"src/ios/GADRequestError.h"
/>
<
source-file
src
=
"src/ios/libGoogleAdMobAds.a"
framework
=
"true"
/>
<
framework
src
=
"StoreKit.framework"
/>
<
framework
src
=
"AudioToolbox.framework"
/>
<
framework
src
=
"MessageUI.framework"
/>
<
framework
src
=
"SystemConfiguration.framework"
/>
<
framework
src
=
"CoreGraphics.framework"
/>
<
framework
src
=
"AdSupport.framework"
/>
</
platform
>
</
plugin
>
Everything looks correct in the posted plugin.xml. Please, make sure the "window.plugins.AdMob == undifined" check is being executed after the deviceReady event. Otherwise it is very likely that the AdMob will be undefined.
If the above is not the case, please contact us again and we will help you get to the bottom of this.
Regards,
Kaloyan
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
document.addEventListener('deviceready', function () {
navigator.splashscreen.hide();
var admob_ios_key = 'a151e6d43c5a28f';
var admob_android_key = 'a151e6d65b12438';
var adId = (navigator.userAgent.indexOf('Android') >=0) ? admob_android_key : admob_ios_key;
if ( window.plugins.AdMob ) {
var am = window.plugins.AdMob;
am.createBannerView(
{
'publisherId': adId,
'adSize': am.AD_SIZE.BANNER,
'bannerAtTop': true
}, function() {
am.requestAd( { 'isTesting':false }, function() {
am.showAd( true );
}, function() {
alert('failed to request ad');
})
}, function(){
alert( "failed to create ad view" );
});
} else {
alert('AdMob plugin not available/ready.');
}
}, false);
Plugin.xml is as follows:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
plugin
xmlns
=
"http://apache.org/cordova/ns/plugins/1.0"
xmlns:android
=
"http://schemas.android.com/apk/res/android"
id
=
"com.rjfun.cordova.plugin.admob"
version
=
"1.1"
>
<
name
>AdMob</
name
>
<
description
>Add AdMob support</
description
>
<
author
>Liming Xie</
author
>
<
license
>MIT</
license
>
<
engines
>
<
engine
name
=
"cordova"
version=">=2.9" />
</
engines
>
<
plugin
name
=
'AdMob'
value
=
'com.google.cordova.plugin.admob'
/>
<
js-module
src
=
"www/AdMob.js"
name
=
"AdMob"
>
<
clobbers
target
=
"window.plugins.AdMob"
/>
</
js-module
>
<
source-file
src
=
"src/android/libs/GoogleAdMobAdsSdk-6.4.1.jar"
target-dir
=
"libs"
/>
<!-- android -->
<
platform
name
=
"android"
>
<!-- <dependency id="com.google.playservices" version=">=15.0.1"/> -->
<
config-file
target
=
"res/xml/config.xml"
parent
=
"/*"
>
<
feature
name
=
"AdMob"
>
<
param
name
=
"android-package"
value
=
"com.rjfun.cordova.plugin.AdMob"
/>
</
feature
>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/manifest/application"
>
<
meta-data
android:name
=
"com.google.android.gms.version"
android:value
=
"4323000"
/>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/manifest/application"
>
<
activity
android:configChanges
=
"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:name
=
"com.google.android.gms.ads.AdActivity"
/>
</
config-file
>
<
config-file
target
=
"AndroidManifest.xml"
parent
=
"/*"
>
<
uses-permission
android:name
=
"android.permission.INTERNET"
/>
<
uses-permission
android:name
=
"android.permission.ACCESS_NETWORK_STATE"
/>
</
config-file
>
<
source-file
src
=
"src/android/AdMob.java"
target-dir
=
"src/com/rjfun/cordova/plugin"
/>
<
source-file
src
=
"src/android/libs/google-play-services.jar"
target-dir
=
"libs"
/>
</
platform
>
<!-- ios -->
<
platform
name
=
"ios"
>
<
config-file
target
=
"config.xml"
parent
=
"/*"
>
<
feature
name
=
"AdMob"
>
<
param
name
=
"ios-package"
value
=
"CDVAdMob"
/>
</
feature
>
</
config-file
>
<
header-file
src
=
"src/ios/CDVAdMob.h"
/>
<
source-file
src
=
"src/ios/CDVAdMob.m"
/>
<
header-file
src
=
"src/ios/GADAdMobExtras.h"
/>
<
header-file
src
=
"src/ios/GADAdNetworkExtras.h"
/>
<
header-file
src
=
"src/ios/GADAdSize.h"
/>
<
header-file
src
=
"src/ios/GADBannerView.h"
/>
<
header-file
src
=
"src/ios/GADBannerViewDelegate.h"
/>
<
header-file
src
=
"src/ios/GADInterstitial.h"
/>
<
header-file
src
=
"src/ios/GADInterstitialDelegate.h"
/>
<
header-file
src
=
"src/ios/GADRequest.h"
/>
<
header-file
src
=
"src/ios/GADRequestError.h"
/>
<
source-file
src
=
"src/ios/libGoogleAdMobAds.a"
framework
=
"true"
/>
<
framework
src
=
"StoreKit.framework"
/>
<
framework
src
=
"AudioToolbox.framework"
/>
<
framework
src
=
"MessageUI.framework"
/>
<
framework
src
=
"SystemConfiguration.framework"
/>
<
framework
src
=
"CoreGraphics.framework"
/>
<
framework
src
=
"AdSupport.framework"
/>
</
platform
>
</
plugin
>
Any suggestions on trying to get this to work?
Regards,
Andrew
Because of the high interest in the AdMob plugin I made a very simple app that implements it.
Please find it attached to this reply. It works both for Android and iOS and it is tested on Android 4.3 and iOS 7.1 versions.
Note that you have to replace the keys below with yours from apps.admob.com :
var
admob_ios_key =
'ca-app-pub-1882245665150742/5173927112'
;
var
admob_android_key =
'ca-app-pub-1882245665150742/7348664319'
;
Thanks.
Regards,
Zdravko
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
Got it all working on both Android and iOS.
Thanks again,
Andrew
Has anybody got this to work with Telerik AppBuilder?
Without an option to monetize your apps the framework is a waste of time!
Are there any other options to add adverts using Cordova and AppBuilder?
Can you please retest this sample and give an update?
The app is working as expected.
Do you by any chance test the app in our Simulator or via AppBuilder Companion app?
If this is the case notice that both tools do not support custom plugins and the best approach to test this app is to deploy it as described here or install the app manually using the build package.
Thanks.
Regards,
Zdravko
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
am going to try and work on it tonight, but thought you might have some insight for me before i start hitting my head on the wall.. :)
Unfortunately, the solution provided by Zdravko does not support Window Phone. Further, my search for another possible approaches did not find anything that could help. Nevertheless, if we come to something appropriate, we will let you know right away.
Thank you for the understanding.
Regards,
Kaloyan
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
The latest AdMob plugin contains teh Windows Phone 8 support. Has anyone tried it?
I took the sample app from Zdravko, updated the plugin directory with the new version here: https://github.com/floatinghotpot/cordova-plugin-admob.
When I "Build & Deploy" I get the following error:
[2014-06-18 08:12:23.563] Log (Info,None): Project "AdTest.proj" (default targets):
Error: The "ResolveAssemblyReference" task failed unexpectedly.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Unexpected CopyLocal flag.
at Microsoft.Build.Tasks.CopyLocalStateUtility.IsCopyLocal(CopyLocalState state)
at Microsoft.Build.Tasks.ResolveAssemblyReference.LogResults(ReferenceTable dependencyTable, DependentAssembly[] idealAssemblyRemappings, AssemblyNameReference[] idealAssemblyRemappingsIdentities, ArrayList generalResolutionExceptions)
at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, OpenBaseKey openBaseKey, CheckIfAssemblyInGac checkIfAssemblyIsInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader)
at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() in C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1605,5)
Error: Could not copy the file "\\icewin1.telerik.local\t\64ed1052f356\bin\AdTest.xap" because it was not found.
Done building project "AdTest.proj" -- FAILED.
I noticed the 'UnexpectedCopyLocal' flag, and i tried it in the Visual Studio extention, and changed the Build Action from Content to Compile.
Now I get:
C:\Users\Daniel\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\c2f151hw.s1z\Targets\Build.targets(158,3): error : Server build failed. Server output: Project "AdMob_Test.proj" (default targets):
Error: Error during processing of action! Attempting to revert...
Done building project "AdMob_Test.proj" -- FAILED.
.
Done building project "AdMob_Test.iceproj" -- FAILED.
Build FAILED.
Not one of the more useful error messages i have seen.. :)
Oh Telerik Gurus, and wisdom to impart?
https://inneractive.jira.com/wiki/display/DevWiki/JavaScript+Ad+Tag
Here is my ads.js file. I added the setInterval to make it refresh.
setInterval(
"ia.rfAd();"
, 30000);
try
{
(
function
() {
console.log(
"GetInnerActiveAd() Start"
);
if
(
typeof
ia ===
'undefined'
) {
ia = {};
}
var
ad_ios_key =
'GreaterVisions_DogeCoin_iPhone'
;
var
ad_android_key =
'GreaterVisions_DogeCoin_Android'
;
var
ad_winphone_key =
'GreaterVisions_DogeCoin_WP'
;
console.log(
"UserAgent: "
+ navigator.userAgent);
//default AD Key
var
adId = ad_winphone_key;
if
(navigator.userAgent.indexOf(
'Android'
) >= 0)
adId = ad_android_key;
if
(navigator.userAgent.indexOf(
'iPhone'
) >= 0)
adId = ad_ios_key;
if
(navigator.userAgent.indexOf(
'iPad'
) >= 0)
adId = ad_ios_key;
var
width = screen.width;
var
height = screen.height;
console.log(
"Ad Key: "
+ adId);
console.log(
"Screen Height: "
+ height);
console.log(
"Screen Width: "
+ width);
// CHANGE AD SETTINGS BELOW.
// More details about the different parameters can be found here:
// https://inneractive.jira.com/wiki/display/DevWiki/JavaScript+Ad+Tag#JavaScriptAdTag-RequestParameters
ia.adSettings = {
APP_ID: adId,
IS_MOBILE_WEB:
false
,
IS_ORMMA_SUPPORT:
false
,
IS_MRAID_SUPPORT:
false
,
IS_VIDEO_SUPPORT:
false
,
IS_FLOATING_BANNER:
false
,
IS_INTERSTITIAL_AD:
false
,
IMEI_MD5:
''
,
IMEI_SHA1:
''
,
IMSI_MD5:
''
,
IMSI_SHA1:
''
,
ANDROID_ID_MD5:
''
,
ANDROID_ID_SHA1:
''
,
IDFA:
''
,
IDFV:
''
,
PACKAGE_NAME:
''
,
// In Android - The application name as a reverse domain notation string (e.g., 'com.inneractive.adTag'). In iOS - the App Store Id from the iTunes URL (e.g., "123456789" for the following iTunes link: 'https://itunes.apple.com/iw/app/myApp/id123456789?mt=8').
CATEGORY:
''
,
// e.g., Music
AGE:
''
,
GENDER:
''
,
KEYWORDS:
'Finance,bitcoin,doge,dogecoin,money'
,
// e.g., Rock,Pop,Jazz,Blues
LOCATION:
''
,
GPS_COORDINATES:
''
,
DEVICE_WIDTH: width,
// resolution width of the device
DEVICE_HEIGHT: height,
// resolution height of the device
MOBILE_NETWORK_CODE:
''
,
MOBILE_COUNTRY_CODE:
''
,
NETWORK:
''
,
// values are 3G or WIFI
REQUIRED_WIDTH:
''
,
REQUIRED_HEIGHT:
''
,
FAILOVER:
''
};
console.log(
"Ad Done"
);
// CHANGE AD SETTINGS ABOVE.
})();
}
catch
(e) {
console.log(
"AD failed: "
+ e.message);
}
I inserted the iaAdPlaceholder div in the footer section so it would show up right above the button bar. (I'm using the KendoUI layout)
<!--Layout-->
<
div
data-role
=
"layout"
data-id
=
"tabstrip-layout"
>
<!--Header-->
<
div
data-role
=
"header"
>
<
div
data-role
=
"navbar"
>
<
span
data-role
=
"view-title"
></
span
>
</
div
>
</
div
>
<!--Footer-->
<
div
data-role
=
"footer"
>
<
div
id
=
'iaAdPlaceholder'
class
=
"OtherAd"
></
div
>
<
div
data-role
=
"tabstrip"
>
<
a
id
=
"cmdHome"
href
=
"#/"
data-icon
=
"home"
>Home</
a
>
<
a
href
=
"#tabstrip-calculator"
data-icon
=
"compose"
>Calculator</
a
>
<
a
href
=
"#tabstrip-settings"
data-icon
=
"settings"
>Settings</
a
>
<
a
href
=
"#tabstrip-about"
data-icon
=
"about"
>About</
a
>
</
div
>
</
div
>
</
div
>
I added some CSS to deal with Android's button bar being at the top.
.OtherAd {
text-align
:
center
;
width
:
100%
;
}
.AndroidAd {
position
:
fixed
;
bottom
:
0
;
text-align
:
center
;
width
:
100%
;
}
And a quick script to toggle those CSS Classes in the deviceready code.
if
(device.platform ==
"Android"
) {
$(
"#iaAdPlaceholder"
).addClass(
"AndroidAd"
).remove(
"OtherAd"
);
}
I am sure there are better ways of doing some of this, but it does work for me.. :)
I got it working on the real device without the AppBuilder Companion App.
It is actually very easy with the latest version of the plugin. I will write up the instructions in a separate post.
1. Download the following two cordova plugins as zip files (Use Download ZIP button)
AdMob plugin at https://github.com/floatinghotpot/cordova-plugin-admob
and
Google Play Services plugin at https://github.com/MobileChromeApps/google-play-services
Google Play Services is a dependency plugin for AdMob plugin
2. Create a new project in Telerik Platorm by selecting "AppBuilder Hybrid Project". I used just the "Blank (Javascript) template, but you can use any.
3. In Project Navigator in Telerik Platform, right click on "Plugins" and select "Import Plugin" and repeat the procedure to import both zip files from step 1
4. Expand "Plugins -> google-play-services-master" folder and open the "version.xml " file. Select and copy the version value inside this element <integer name="google_play_services_version">4452000</integer>
5. Open the "plugin.xml" file in the same folder and replace "@integer/google_play_services_version" in <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> with the version value you copied, so it would look like this <meta-data android:name="com.google.android.gms.version" android:value="4452000" />
6. Expand "Plugins -> cordova-plugin-admob-master" folder, open the "plugin.xml" file and repeat the same procedure as in step 5, replacing the same element with the version value
7. Expand the "test" folder in "Plugins -> cordova-plugin-admob-master" folder and copy the "index.html" over to the main "index.html" file in the root of the project, overwriting the existing file
8. Open the "index.html" file in the root folder and replace the Android and iOS keys with your own
var admob_ios_key = 'ca-app-pub-5555555555555/555555555555';
var admob_android_key = 'ca-app-pub-5555555555555/555555555555';
9. For Windows Phone 8, open the following file "Plugins -> cordova-plugin-admob-master -> src -> wp8 -> GoogleAds.XML"
Find the following element and replace the AdUnitId with your own
<member name="P:GoogleAds.AdRequest.AdUnitId">
<summary>
ca-app-pub-5555555555555/555555555555
</summary>
</member>
10. To test the app on real device, on Android for example, use "Run->Build->Android->App Package". Do not use Appbuilder, that does not work either in simulator or in AppBuilder Companion App on real device
Enjoy
Telerik guys, please look into the build environment, there is something misconfigured there.
@Alex I managed to reproduce the build error for Windows Phone. It seems like something in the WP sources of the plugin is messed up. However, we will further investigate this on our side and will let you know of the results.
@Daniel thank you for sharing your solution on that matter with the community.
Regards,
Kaloyan
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
I am happy to share that the AdMob plugin is now build-able for WP8 inside AppBuilder. One of our developers contributed the needed change to the official plugin repository. It was immediately merged. So, please download the latest version of the plugin and check if it is working on your sides.
Further, I have attached a demo project that should work well on WP8 devices.
I hope this helps.
Regards,
Kaloyan
Telerik
Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!
I keep getting this:
Failed to install 'com.rjfun.cordova.plugin.admob':Error: 404 Not Found: com.google.admobsdk-ios
at RegClient.<anonymous> (/Users/builder/BpcTooling/Cordova3/3.5.0/node_modules/plugman/node_modules/npm/node_modules/npm-registry-client/lib/request.js:268:14)
at Request.self.callback (/Users/builder/BpcTooling/Cordova3/3.5.0/node_modules/plugman/node_modules/npm/node_modules/request/index.js:148:22)
at Request.EventEmitter.emit (events.js:98:17)
at Request.<anonymous> (/Users/builder/BpcTooling/Cordova3/3.5.0/node_modules/plugman/node_modules/npm/node_modules/request/index.js:876:14)
at Request.EventEmitter.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Users/builder/BpcTooling/Cordova3/3.5.0/node_modules/plugman/node_modules/npm/node_modules/request/index.js:827:12)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)
404 Not Found: com.google.admobsdk-ios
Thank you for reporting this. The failure was due to a bug on our server side, which we fixed right away.
Please, check if everything is working as expected now and let us know if there are any further issues.
Excuse us for any inconvenience this has caused.
Regards,
Kaloyan
Telerik
Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.
thanks a lot Kaloyan