How to integrate "Admob" with Cocos2d-x V3.0rc0&beta2 Android Project

Hi All
Follow by above Ryeeeeee’s source code. Can u write me functions that allow Ads visibile and invisibile
thanks

The game is crashing if I say showad with vmAborting in logcat… do I need to make any changes to cocos2dActivity.java since I am running it on 2.2.2?

Dont I have to import and initialize this in game.java???

Also is the game or bg showing for you guys now??

@fishPRG - No clue on how to use the plugin… care to show how??

I am not able to get this work on 2.2.2 … can someone guide??? I get the following error…

03-20 17:33:03.363: E/Trace(796): error opening trace file: No such file or directory (2)
03-20 17:33:03.723: D/AndroidRuntime(796): Shutting down VM
03-20 17:33:03.723: W/dalvikvm(796): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-20 17:33:03.743: E/AndroidRuntime(796): FATAL EXCEPTION: main
03-20 17:33:03.743: E/AndroidRuntime(796): java.lang.RuntimeException: Unable to start activity ComponentInfo{lingerers.example.com/org.cocos2dx.cpp.Cocos2dxActivity}: java.lang.IllegalArgumentException: Unable to find native library: main

@siddharthshekar Sorry, it works only with v3.0.

thanks… :frowning:

@Matuda it has to add Ad. with another way in Cocos2d-x v2.x.

hey… i got it to work in 2.2.3 … but when i lock and unlock… ad disappers… i have to wait for another ad to load from revmob … and then the banner will show again… why is this??? i even change the color to black and change it white after load… ??

maybe i will post a new topic as it is related to 2.2.2.

Hello Ryeeeeee,

I am using cocos2dx 2.2.2 and have added Android 3.2 (13) as min SDK for my project.
i have added the above code for admob in my game, it shows me the Ad but the rest of the screen goes black.

Any suggestions.

@anupgupta
Sorry, this post is only available to cocos2d-x 3.0. In cocos2d-x 2.x, my advice is that adding Ad to the parent view of GLSurfaceView.

not working in cocos2d-x3.0rc + google play services 16

help me.

1)i try this, PopupWindow show ,but the banner admob not show, although “onAdLoaded()”
2)i try to show / hidden PopupWindow, but not working
@Override
public void onAdLoaded() {
Log.d(“adView”, “Did Receive Ad”);
//adView.show();
super.onAdLoaded();
mainLayout.setVisibility(LinearLayout.VISIBLE);
adView.setVisibility(LinearLayout.VISIBLE);
}

	                @Override
	                public void onAdFailedToLoad(int errorCode) {
	                	 Log.d("adView", "failed to receive ad (" + errorCode + ")");
	                	 super.onAdFailedToLoad(errorCode);
	                	 mainLayout.setVisibility(LinearLayout.GONE);
	                	 adView.setVisibility(LinearLayout.GONE);
	                }

@kyo9999

  1. I will test.
  2. did you try using “popUp.dismiss()” to hide the PopupWindow.

@Ryeeeeee

  1. i find popup showed, but adview(just black area) show nothing too.
    [[http://b333.photo.store.qq.com/psb?/V11estft4Xu2ic/bN3qSHdZHvWcdOJJJo5WGlxfdSh0ZOeHycFsifh6ixM!/b/dHVlfcavEAAA&bo=rAFPAAAAAAABAMU!&rf=photoDetail]]

  2. the code don’t may mainLayout/layout/adview to hidden
    @Override
    public void onAdFailedToLoad(int errorCode) {
    Log.d(“adView”, “failed to receive ad (” + errorCode + “)”);
    super.onAdFailedToLoad(errorCode);
    mainLayout.setVisibility(LinearLayout.GONE);
    adView.setVisibility(AdView.GONE);

                     	 _activity.runOnUiThread(new Runnable() {
     				    	    @Override
     				    	    public void run() {
     				    	    	popUp.dismiss(); 
     				    	    }
     				    	   });
                     }

Thanks @Ryeeeeee

As we know “androidNativeActivity” has been changed in RC1.
Do we still to modify “Cocos2dxActivity.java” ?
If i use the one on this thread, Eclipse report a error:
“The public type must be defined in its own file”

EDIT:
In RC1 “Cocos2dxActivity.java” dose not exist anymore. just “AppActivity.java”

rc1 more different fom rc0, such as public class AppActivity extends Cocos2dxActivity, it can’t work, i change my code to pre code, it work.

RelativeLayout layout = new RelativeLayout(this); // 相对布局
//layout.setOrientation(RelativeLayout.VERTICAL); // 横版的顶部
addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
adView = new AdView(this); // 创建 adView, admob android BorrowArrows
adView.setAdUnitId("");
adView.setAdSize(AdSize.BANNER);
RelativeLayout.LayoutParams layoutParams =
new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setLayoutParams(layoutParams);
layout.addView(adView); // 在其中添加 adView
// 启动一般性请求。
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest); // 启动一般性请求并在其中加载广告

        Log.i("ADMOB View: layout = ", layout.getWidth() + "," + layout.getHeight()); // 0, 0
        Log.i("ADMOB View: adView = ", adView.getWidth() + "," + adView.getHeight());

@kyo9999 Please can you explain more?
What have to do exactly in RC1 to enable Admob?

Thanks in advance.

@victory144 rc1 use this: http://www.uaialternativa.com/admob-cocos2d-x/

@victory144 like this:
http://www.uaialternativa.com/admob-cocos2d-x/

How to add admob to a project created in cocos2d-js , especially in the cocos2d beta editor.

@Ryeeeeee Thank you for this tutorial! Great work! +1

This should be updated to 3.1.1 and added to the official documentation in the Android section.
Monetization of the final app could be a new chapter for the docs (Android, iOS, etc).

1 Like

I used this project in a demonstration where many people created a simple AdMob application for Cocos2d-x.

Everyone found it fairly easy to set up.