Thursday, May 14, 2015

Cocos2dx: Admob Android

After doing the steps for iOS Admob, continue with the steps below for Android.

Copy the files JNIHelpers.cpp and JNIHelpers.h from folder External Cocos Helper Android Frameworks/Classes to your project's Classes folder:

Copy the files SonarFrameworks.cpp and SonarFrameworks.h to the Classes folder of your cocos project:

Copy the file SonarFrameworkSettings.xml file from res/values to the res/values of your
( Do not overwrite the res folder else you will lose the drawable folders and also the strings.xml )

Then, copy the src folder and overwrite the src folder in

And copy the AndroidManifest.xml and replace the same file in
Open the AndroidManifest.xml file in and make the following changes.
Change the package name to your packagename.

Edit the file in jni folder:

to add the additional classes as follows:

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/Bird.cpp \
                   ../../Classes/GameOverScene.cpp \
                   ../../Classes/GameScene.cpp \
                   ../../Classes/MainMenuScene.cpp \
                   ../../Classes/SplashScene.cpp \
                   ../../Classes/Pipe.cpp \
                   ../../Classes/JNIHelpers.cpp \

The added files are:

   ../../Classes/JNIHelpers.cpp \

Then build the by running

Open Eclipse and import libcocos2dx and your HelloCocos project. Then import google-play-services-lib:

Then, add it as a library:

Then add the google-play-services-lib.jar:

And also make sure to Order and Export it by checking the checkbox:

Then, open the AndroidManifest.xml file and make the following changes.
Enabled the following tags (by uncommenting them ), below is what it should look like:

<!-- Required for Google Play Services 
            android:value="@string/google_play_game_app_id" /> -->
            android:value="@integer/google_play_services_version" /> 
<!-- End here requirement for Google Play Services -->

<!-- Required for AdMob -->
        <activity android:name=""
            android:theme="@android:style/Theme.Translucent" />
<!-- End here requirement for AdMob -->

Enable only the following permissions and disable the rest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Then open SonarFrameworkSettings.xml and enter the admob ids:

Copy the AdMob folder from Frameworks folder to folder

Click File, Refresh the Eclipse project to see the new Admob framework:

Open the file and set Admob to true:

                  public static final boolean USE_ADMOB = true;

That's it. Just run and it will work just like the iOS version.

No comments:

Post a Comment