Google AdMob extension for OpenFL applications. Working on both Android and iOS. Code is heavily based on NMEX extension which is pretty much outdated right now. This forked version updates the Google Play Services library to the revision 20. It was only tested on Android.
Instructions
- Clone this repo using
haxelib git admob https://github.com/mkorman9/admob-openfl
command - Include extension to your project
<haxelib name="admob" />
- Import AD class
import admob.AD;
- Setup ads at the beginning of your code
AD.init(ADMOB_ID, AD.LEFT, AD.BOTTOM, AD.BANNER_PORTRAIT, false);
where arguments are following:
- Ad unit id.
- Position in x axis. Could be
AD.LEFT
orAD.RIGHT
- Position in y axis. Could be
AD.TOP
orAD.BOTTOM
- Banner size. Could be
AD.BANNER_PORTRAIT
orAD.BANNER_LANDSCAPE
(see google's documentation) - Test mode. Whether enable test ads or not. Default value is false.
- Show banner
AD.show();
- You can hide it anytime by calling
AD.hide();
Prerequisites on iOS
- Add following code to your project.xml
<ios linker-flags="-force_load __PATH_TO_THE_HAXELIB_DIR__/admob/git/ndll/iPhone/libGoogleAdMobAds.a" />
don't forget to replace __PATH_TO_THE_HAXELIB_DIR__
with real path to your haxelib, in most cases it will be /usr/lib/haxe/lib
- After creating XCode project, drag libGoogleAdMobAds.a to Project Settings->Build Phases->Link with binaries
- (Optional) You can rebuild binaries on Mac OSX using five simple commands:
cd __PATH_TO_THE_HAXELIB_DIR__/admob/git/project
haxelib run hxcpp Build.xml -Diphoneos
haxelib run hxcpp Build.xml -Diphoneos -DHXCPP_ARMV7
haxelib run hxcpp Build.xml -Diphonesim
haxelib run hxcpp Build.xml
Prerequisites on Android
- Copy android-template directory to your project
- Add following code to your project.xml:
<java path="android-template/libs/google-play-services.jar" if="android" />
<template path="android-template/AndroidManifest.xml" rename="AndroidManifest.xml" if="android" />
<template path="android-template/src/org/haxe/lime/GameActivity.java" rename="src/org/haxe/lime/GameActivity.java" if="android" />
<template path="android-template/res" rename="res" if="android" />