How to Add AdMob to a Cocos2d-X Project

author
3 minutes, 46 seconds Read

There are new things from Firebase at the I/O.

This guide shows how to include AdMob in a project. You can create a new cocos project from the command line if you don’t have a project at all.

cocos new MyGame -l cpp

AdMob only supports Cocos2d-x apps for the two platforms. This guide assumes you are only developing a Cocos app for Android/iOS, but you can wrap your entire AdMob integration in order to make sure it’s only executed in mobile app environments.

#endif (CC_TARGET_PLATFORM)…

Prerequisites

You must have following installed on your machine:

  • The latest version of Cocos2d-x
  • Python 2.7 or higher
  • Only required for the development of theANDROID.

Get the AdMob with Firebase C++ SDK

The same directory that contains your proj.android-studio and proj.ios_mac directories should be used to extract the files. The folder has a name.

Set up iOS

The following steps will show you how to import the Firebase SDK.

Cocoa Pods must be used for this integration.

You can add Firebase to your app. If your project is inside the proj.ios_mac/ directory, it should reference a file from the internet. Go to your proj.ios_mac/ directory and create a Podfile with the following information: source ‘https://github.com/Cocoa Pods/Specs.git’ platform :ios, ‘7.0’ At this point, you have both the Firebase and the Mobile Ads SDK in your project. Cocoa Pods gives warnings about missing money. Add $(inherited) to the bottom of the list for each of the build set best website to learn mobile app developmenttings for the My Game-mobile target.

  • Preprocessor Macros

Library Search Paths can be added to your Framework Search Paths. You need to include a reference to the libraries you want to use Click on the project you want to add files to. The firebase.framework and firebase_admob.framework are in the universal directory. If you want to add the frameworks, uncheck the copy items option. The settings you added in the previous step let Xcode find the frameworks. The GameController.framework can be added to build phases. AdMob’s App Transport Security guide can be used to make sure ads behave correctly.

You should be able to build and run the app.

Cocoa Pods has a side effect of making it harder to build theiOS app using cocos run -p from the command line.

You now have your project set up with AdMob. You’re ready to start.

Set up Android

The following steps will show you how to import the Firebase SDK.

Add the lines shown in bold to your proj.android-studio/app/jni/Android.mk. Make sure to set theDIR to the local path when you download the SDK. The project’s root directory has the path to the Firebase C++ SDK located in it. APP_ABI := armeabi-v7a x86 The ads package should be included in your app/build.gradle.

The AdMob components are included in the Firebase C++ SDK.

C++ integration

The next step is to load some ads after your projects are referenced in the SDK.

Initialize Firebase and AdMob

It is recommended to start with AdMob as early as possible. The AppDelegate.dll file is the most natural place to add this code.

AppDelegate.cpp

“firebase/admob.h” USING_NS_CC; bool App::applicationDidFinishDelegate

The Firebase app requires a JNI environment. The JniHelper class is used in the sample code above.

Get an ad parent

AdMob requires a fire base to be used to store each format. This object is related to an activity on both phones. The following class creates a method that returns the appropriate object for the platform.

FirebaseHelper.h

#include “fire base/admob/types.h” There will be a J object pointing to the activity. The root view of the view controller is where it’s pointed.

FirebaseHelper.cpp

#include “FirebaseHelper.h” and “platform/android/jni/JniHelper.h”

You can add this class to your project. Make sure to add this file to your project in order to get the local source files in your project.

hellocpp/main.cpp ../././Classes/AppDelegate.dll ../././Classes/HelloWorldScene.dll

Load a banner ad

A complete example of how to load a banner ad is shown.

#include “firebase/admob.h”, “firebase/admob/types.h”, “firebase/app.h”, and “firebase/future.h” “Loading a banner.”; banner_view: Show; firebase: AdRequest my_ad_request:

What’s next

With the integration of the Mobile Ads SDK into your Cocos2d-x project, you can use your preferred format and interact with it.

Similar Posts

Leave a Reply

Your email address will not be published.