Create a Custom AdMob Plugin for Phonegap Build (for iOS and Android)
Everything in my Phonegap Build app is working, including the Analytics and FacebookConnect plugins. However, now I would like to add AdMob ads.
Phonegap Build does not provide a built-in plugin for AdMob, but according to the Phonegap Build Plugins page, you can now add your own custom plugins (see Contributing Plugins at the bottom of the page).
PhoneGap Plugins can be made compatible with PhoneGap Build with the use of a plugin.xml file...
The Phonegap Build Plugins page references the Child Browser plugins.xml on GitHub as an example of how to setup the custom plugin.xml. Below is the content of the Child Browser plugin.xml.
I'm not sure what aspects of this file I need to modify and what to modify them to. I think I have correctly setup the file structure of the Phonegap AdMob Plugins for both iOS and Android (see the file structure below), but I'm not sure how to reference these files correctly in the plugin.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.phonegap.plugins.childbrowser"
version="3.0.4">
<name>Child Browser</name>
<asset src="www/childbrowser.js" target="childbrowser.js" />
<asset src="www/childbrowser" target="childbrowser" />
<!-- android -->
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.phonegap.plugins.childBrowser.ChildBrowser"
android:label="@string/app_name">
<intent-filter>
</intent-filter>
</activity>
</config-file>
<!-- Cordova 1.5 - 1.9 -->
<config-file target="res/xml/plugins.xml" parent="/plugins">
<plugin name="ChildBrowser"
value="com.phonegap.plugins.childBrowser.ChildBrowser"/>
</config-file>
<!-- Cordova 2.0.0 -->
<config-file target="res/xml/config.xml" parent="/cordova/plugins">
<plugin name="ChildBrowser"
value="com.phonegap.plugins.childBrowser.ChildBrowser"/>
</config-file>
<source-file src="src/android/ChildBrowser.java"
target-dir="src/com/phonegap/plugins/childBrowser" />
</platform>
<!-- ios -->
<platform name="ios">
<plugins-plist key="ChildBrowser"
string="ChildBrowserCommand" />
<resource-file src="ChildBrowser.bundle" />
<resource-file src="ChildBrowserViewController.xib" />
<header-file src="ChildBrowserCommand.h" />
<header-file src="ChildBrowserViewController.h" />
<source-file src="ChildBrowserCommand.m" />
<source-file src="ChildBrowserViewController.m" />
</platform>
</plugin>
App File Structure
/index.html
/config.xml
/adMob
/plugin.xml
/src
/iOS
/GADAdMobExtras.h (from AdMob iOS SDK)
/GADAdNetworkExtras.h (from AdMob iOS SDK)
/GADAdSize.h (from AdMob iOS SDK)
/GADBannerView.h (from AdMob iOS SDK)
/GADBannerViewDelegate.h (from AdMob iOS SDK)
/GADInterstitial.h (from AdMob iOS SDK)
/GADInterstitialDelegate.h (from AdMob iOS SDK)
/GADRequest.h (from AdMob iOS SDK)
/GADRequestError.h (from AdMob iOS SDK)
/libGoogleAdMobAds.a (from AdMob iOS SDK)
/AdMobPlugin.h (from Phonegap Plugin for iOS)
/AdMobPlugin.js (from Phonegap Plugin for iOS)
/AdMobPlugin.m (from Phonegap Plugin for iOS)
/android
/AdMobPlugin.java (from Phonegap Plugin for Android)
/AdMobPlugin.js (from Phonegap Plugin for Android)
/GoogleAdMobAdsSdk-6.2.1.jar (from AdMob Android SDK)
Phonegap Plugin for iOS
AdMob iOS SDK
Phonegap Plugin for Android
AdMob Android SDK
I make the plugin
But it's was refused on "PhoneGap Build", because it contains Google Binary files…
Today, you don't have no solution to use Admob on "PhoneGap Build" project.
This is an old unanswered question as since today it was impossible. But Phonegap has announced a change in their rules: see here, so now it's possible to use external plugins. To add Admob Ads to your Phonegap Build app, edit your config.html
file and place the following code:
<gap:plugin name="phonegap-admob" source="npm" />
I'm the author of the plugin and you can see a live demo app (for Android only) here