It's Cocos2d-x implementation of Admob for Native Gateway.
Native Gateway allows you to create flexible native extension for cross-platform engines in easy way.
Before start with Admob integration, please go through this document in order to integrate Native Gateway to your project: https://github.com/vedi/native-gateway-cocos2dx
Draw your attention this repository includes all needed dependency including Admob libs as well.
Drag&Drop repository folder to your project in XCode.
- In
Android.mkof your project include files fromcocos2dxfolder to your sources, - Add jar-files from
androidfolder tolibsof your project. - Add
google-play-services_libfromandroidfolder as dependency of your project. - Add in AndroidManifest.xml
<application>
...
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
...
</application>
...
<uses-permission android:name="android.permission.INTERNET"/>
- Add repository as submodule of your project typing in your
Classesfolder:
git submodule add https://github.com/smallkot/admob-bunch-cocos2dx.git admob-bunch
- Create static links for jars in
proj.android/libsinstead of copying:
ln -s ../../Classes/admob-bunch/android/admob-bunch.jar admob-bunch.jar
- Create a static link for
google-play-services_lib(I put it toandroid_depsfolder at roo of my project):
ln -s ../Classes/admob-bunch/android/google-play-services_lib google-play-services_lib
- Put new record to your
project.properties. In my case it's:
android.library.reference.2=../android_deps/google-play-services_lib
Initialize AdmobBunch:
#include "CCAdmobBunch.h"
...
CCAdmobBunch::initialize();Create banner
#include "CCAdmobBunch.h"
...
CCAdmobBunch::createBanner("ca-app-pub-......", aGADAdSizeBanner);The banner is created only once at the start of the game.
Show banner
CCAdmobBunch::getInstance()->showBanner(0, 0, Director::getInstance()->getWinSize().width, Director::getInstance()->getWinSize().height, kBannerGravityBottomCenter);If gravity is kBannerGravityNone the first two parameters are responsible for filling the banner.
Hide banner
CCAdmobBunch::getInstance()->hideBanner();Create interstitial
CCAdmobBunch::getInstance()->createInterstitial("ca-app-pub-65......");Show interstitial
CCAdmobBunch::getInstance()->showInterstitial();Explore CCAdmobBunch.h. You'll find the simple things here, which reflect well to admob API.
This repository includes prebuild native libraries, the sources are available at the following URLs: