Include AdMob Banner on Cocos2d-x Android Game


In this post we will show a piece of code that will help you to add an admob banner on your cocos2d-x game in android.

Firstly, you need to setup the google play services on your app.
Then you need to include on your AndroidManifest.xml the Admob activity and the required permissions.

<activity android:name=""

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

Then on your Activity, you need to put this piece of code on the onCreate method:

protected void onCreate(Bundle savedInstanceState) {
		AdView adView = new AdView(this);
		adView.setAdUnitId("YOUR AD UNIT ID");

		RelativeLayout relativeLayout=new RelativeLayout(this);
		RelativeLayout.LayoutParams layoutParams1=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
		RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
		layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
		AdRequest adRequest = new AdRequest.Builder()

		relativeLayout.addView(adView, layoutParams);
		this.addContentView(relativeLayout, layoutParams1);


I hope this help.

See you on the next post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s