Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Chartboost Plugin Implementation — Gideros Forum

Chartboost Plugin Implementation

zaniarzaniar Member
edited December 2012 in Plugins
I'm trying to implement ChartBoost plugin for Android. The plugin should be accessible via Lua code.

Afaik, the initialization of ChartBoost must be called inside onCreate method. The plugin went error when I initialize it outside onCreate method. The problem is I can't set appId and appSignature via Lua code if ChartBoost must be initialized on onCreate.

When did the plugin's onCreate method called?
Is plugin's Java class instantiated/executed automaticaly when the player started?

fyi, I following @ar2rsawseen's tutorial and using the pattern of GoogleBilling plugin.

Likes: arcadia, krisis

+1 -1 (+2 / -0 )Share on Facebook
«1

Comments

  • atilimatilim Maintainer
    edited December 2012
    > When did the plugin's onCreate method called?
    At the onCreate function of Activity.

    There are two points here:
    1. Your onCreate function should be static like:
    public static void onCreate(Activity activity)
    2. onCreate is called before the initialization of Gideros.
  • here the help page about Android integration: https://help.chartboost.com/documentation/android

    the following code need to be called inside onCreate method
    // Notify the beginning of a user session
    this.cb.startSession();
    I need a method just like startSession in Flurry plugin. In that method I write the following code:
    // Configure Chartboost
    this.cb = Chartboost.sharedChartboost();
    String appId = "YOUR_APP_ID";
    String appSignature = "YOUR_APP_SIGNATURE";
    this.cb.onCreate(this, appId, appSignature, null);
     
    // Notify the beginning of a user session
    this.cb.startSession();
    then I got this kind of error on logcat:
    Can't create handler inside thread that has not called Looper.prepare()
    that was happened when this.cb.startSession() called on a method other than onCreate.

    Hmm.. I guess I need to learn about Looper.prepare()
  • atilimatilim Maintainer
    Accepted Answer
    I think you should call cb.startSession() with Actvity.runOnUiThread like:
    activity.runOnUiThread(new Runnable() {
        public void run() {
        	cb.startSession();
        }
    });
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Yes it means you need to be on the main UI thread, here is how I did it in AdMob plugin
    public class YourClass{
     
    	//reference to main activity
    	private static WeakReference<Activity> sActivity;
    	public static void onCreate(Activity activity)
    	{
    		//reference to activity
    		sActivity =  new WeakReference<Activity>(activity);
    		try
    		{
    			sActivity.get().runOnUiThread(new Runnable() {
     
    				<a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    				public void run() {
    					//do your stuff here
    				}
    			});
     
    		}
    		catch(Exception ex)	{}
    	}
    }
  • Hey, it works!!

    thanks :-bd
    	static public void startSession(String appId, String appSignature)
    	{	
    		sChartboost = Chartboost.sharedChartboost();
    		sChartboost.onCreate(sActivity.get(), appId, appSignature, null);
     
    		try
    		{
    			sActivity.get().runOnUiThread(new Runnable() {
     
    				<a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    				public void run() {
    					sChartboost.startSession();
    					sChartboost.showInterstitial();
    				}
    			});
     
    		}
    		catch(Exception ex)	{}
    	}

    Likes: ar2rsawseen

    +1 -1 (+1 / -0 )Share on Facebook
  • Next question...
    Can I catch key event on my plugin?

    I tried:
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
    	android.util.Log.v("ChartBoost:onKeyUp", ""+keyCode);
     
    	return true;
    }
    but nothing shown up on logcat
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2012
    @zaniar not exactly like that, it will be a little more difficult (Unless @atilim will unwrap some secret API :) ).

    The easy way would be to add event listener in Lua, that will call somekind of method from your plugin (which calls C funciton, which calls Java function).

    But if you want to automatically register to event, without the need for user to do it in Lua by himself, then you need to do it from C (by getting stage object, then by getting it's addevntlistener method, then by calling it, etc).

    Actually I don't know why, but all this C to Lua bridge (same for Java), seems such a pain. So many things can go wrong and needs to be considered. Not as easy as it is advertised :)
  • NascodeNascode Guru
    edited December 2012
    @ar2rsawseen yes, if there is any detailed official guide from Gideros team to do C bridge to Lua it would help a lot ;)

    for example we could look at Corona Enterprise docs http://docs.coronalabs.com/native/enterprise/ios/index.html
    have fun with our games~
    http://www.nightspade.com
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2012
    @Nascode awesome docs, haven't seen them, will study them more ;)
    There are couple of interesting ideas there
  • zaniarzaniar Member
    edited December 2012
    I modify player's main activity like this:
    <a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    public boolean onKeyUp(int keyCode, KeyEvent event)
    {
    	if(GChartBoost.onKeyUp(keyCode, event) == true)
    		return true;
     
    	if (GiderosApplication.getInstance().onKeyUp(keyCode, event) == true)
    		return true;
     
    	return super.onKeyUp(keyCode, event);
    }
    Now, my plugin can catch key event :D
  • edited January 2013
    Did anyone try this?

    I do as the guide said, except 2 things:

    1.Bind back button instead of menu button.
    2.Keep the following line:
    import com.nightspade.gideros.android.plugins.chartboost.GChartBoost; 
    static private String[] externalClasses = { 
        "com.nightspade.gideros.android.plugins.chartboost.GChartBoost "};
    When I try to change nightspade to my PACKAGE_NAME, my game crash right after Gideros logo appear.

    Config like above, the game works fine however there's no fullscreen ads show as expected :(

    p/s: my Integration Status show green SDK and Analytics show Boot ups = 4..Does this mean my game does have request but in that moment Chartboost has no ads to serve?
  • fxonefxone Member
    edited January 2013
    @thanhquan1512 yes, I've tried with the same result... but I'm still on way of my new project, so I can't now handle this effectively. But I have eye on this.. $-)
  • @thanhquan1512 Chartboost and Revmob are very lack of campaign in Vietnam.
    My Revmob account usually say:
    [RevMob] reason: No ads for this device/country right now, or your App ID is paused.

    :)
    Coming soon
  • @thanhquan1512 Chartboost and Revmob are very lack of campaign in Vietnam.
    My Revmob account usually say:
    [RevMob] reason: No ads for this device/country right now, or your App ID is paused.

    :)
    Thank you. It's hard to test Chartboost here :D I had registered a test device and I hope it will be better.

    For my problem, after integrating Chartboost SDK, I created a new Chartboost publish campaign and now I can see ads. However I still don't know how to control it appearance, I attach ads in back button press event but my game show ads when playing :D

  • fxonefxone Member
    edited January 2013



    For my problem, after integrating Chartboost SDK, I created a new Chartboost publish campaign and now I can see ads.

    @thanhquan1512 Do you use Zaniar's plugin or clean Chartboost SDK?
  • edited January 2013

    @thanhquan1512 Do you use Zaniar's plugin or clean Chartboost SDK?
    I use Zaniar's plugin :) After following the guide to integrate SDK, just remember to activate a publish campaign in Chartboost website to begin (after integrate successful you will have a notification mail from Chartboost guide to next step: create a campaign)

    Likes: fxone

    +1 -1 (+1 / -0 )Share on Facebook
  • edited January 2013
    @zaniar: can you take a look a this crash report, sorry I am noob at plugin. Thank you !!

    My game show chartboost ads at end game. I published last night and there is around 10 impression, 1 crash.

    java.lang.NullPointerException
    at com.nightspade.gideros.android.plugins.chartboost.GChartBoost.onKeyUp(GChartBoost.java:59)
    at com.giderosmobile.android.CupidGameofLoveActivity.onKeyUp(CupidGameofLoveActivity.java:201)
    at android.view.KeyEvent.dispatch(KeyEvent.java:1294)
    at android.app.Activity.dispatchKeyEvent(Activity.java:2078)
    at
  • ScouserScouser Guru
    edited January 2013
    @thanhquan1512: It would appear that GChartBoost.startSession isn't being called, or at least GChartBoost.onStart is being called before GChartBoost.startSession has finished processing. There needs to be some sort of check in place to make sure that sChartboost has actually been initialised.

    Likes: thanhquan1512

    +1 -1 (+1 / -0 )Share on Facebook
  • On a post whoring mission - nothing to see here (It's not my fault! )
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • edited January 2013
    @thanhquan1512: It would appear that GChartBoost.startSession isn't being called, or at least GChartBoost.onStart is being called before GChartBoost.startSession has finished processing. There needs to be some sort of check in place to make sure that sChartboost has actually been initialised.
    Thank you, I am waiting for today crash report, I had better check this;

    chartboost:hasCachedInterstitial()

    before

    chartboost:showInterstitial()

    Thank you :D
  • edited March 2013
    @zaniar
    I try to using chartboost from https://github.com/zaniar/gideros_chartboost

    But when run debug on android device it forces close with error:
    03-08 11:08:50.409: D/dalvikvm(19573): Trying to load lib /data/data/com.yourdomain.yourapp/lib/libchartboost.so 0x413a7548
    03-08 11:08:50.409: W/dalvikvm(19573): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/giderosmobile/android/TestPluginActivity;
    03-08 11:08:50.409: W/dalvikvm(19573): Class init failed in newInstance call (Lcom/giderosmobile/android/TestPluginActivity;)
    (Gideros version 2012.09.10 ,export with encrypt lua file option).

    Here is my project in Gideros an Eclipse.

    https://www.dropbox.com/s/ppdc0xt6yl1u531/TestPlugin.zip
    https://www.dropbox.com/s/i6zch5dggxfclfb/TestPlugin_Android.zip

    Can you take a look and help me?

    Coming soon
  • fxonefxone Member
    edited March 2013
    @vitalitymobile firstly you don't have Android.mk file in jni folder... and sdk/include also from gideros installation, look at top of Zaniar's guide
  • fxonefxone Member
    @all I also must have some trivial error but I reverted my code few times a day and I don't recognize my mistake. Could anyone send proper example folders with this plugin? This is an error statement from Eclipse:
    03-08 06:45:42.560: E/dalvikvm(1278): dlopen("/data/app-lib/com.streetpool-1/libchartboost.so") failed: Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol "gevent_createEventStruct1" referenced by "libchartboost.so"...
  • fxonefxone Member
    edited March 2013
    @fxone hm I only see now some strange put in eclipse error (above) my package is named "com.streetpool-1" not com.streetpool like should be. how to fix it?
  • edited March 2013
    @fxone

    Oop, I think plugin just need .so , java and .jar file.

    I still get error after adding Android.mk and other file. Would you give me some advice please?

    https://www.dropbox.com/s/i6zch5dggxfclfb/TestPlugin_Android.zip

    When run ndk-build I have below error:
    d:\coding\eclipse\Gideros\TestPlugin>ndk-build
    "Compile++ arm  : chartboost <= gchartboost.cpp
    jni/chartboost/gchartboost.cpp: In constructor 'GChartBoost::GChartBoost()':
    jni/chartboost/gchartboost.cpp:18:20: error: 'g_nextgid' was not declared in thi
    s scope
    jni/chartboost/gchartboost.cpp: In destructor 'GChartBoost::~GChartBoost()':
    jni/chartboost/gchartboost.cpp:37:34: error: 'gevent_removeEventsWithGid' was no
    t declared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onCacheInt
    erstitial(jstring)':
    jni/chartboost/gchartboost.cpp:49:3: error: 'gevent_createEventStruct1' was not
    declared in this scope
    jni/chartboost/gchartboost.cpp:53:93: error: 'gevent_enqueueEvent' was not decla
    red in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onCacheMor
    eApps()':
    jni/chartboost/gchartboost.cpp:58:89: error: 'gevent_enqueueEvent' was not decla
    red in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onClickInt
    erstitial(jstring)':
    jni/chartboost/gchartboost.cpp:70:3: error: 'gevent_createEventStruct1' was not
    declared in this scope
    jni/chartboost/gchartboost.cpp:74:93: error: 'gevent_enqueueEvent' was not decla
    red in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onClickMor
    eApps()':
    jni/chartboost/gchartboost.cpp:79:89: error: 'gevent_enqueueEvent' was not decla
    red in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onCloseInt
    erstitial(jstring)':
    jni/chartboost/gchartboost.cpp:91:3: error: 'gevent_createEventStruct1' was not
    declared in this scope
    jni/chartboost/gchartboost.cpp:95:93: error: 'gevent_enqueueEvent' was not decla
    red in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onCloseMor
    eApps()':
    jni/chartboost/gchartboost.cpp:100:89: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onDismissI
    nterstitial(jstring)':
    jni/chartboost/gchartboost.cpp:112:3: error: 'gevent_createEventStruct1' was not
     declared in this scope
    jni/chartboost/gchartboost.cpp:116:95: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onDismissM
    oreApps()':
    jni/chartboost/gchartboost.cpp:121:91: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onFailToLo
    adInterstitial(jstring)':
    jni/chartboost/gchartboost.cpp:133:3: error: 'gevent_createEventStruct1' was not
     declared in this scope
    jni/chartboost/gchartboost.cpp:137:100: error: 'gevent_enqueueEvent' was not dec
    lared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onFailToLo
    adMoreApps()':
    jni/chartboost/gchartboost.cpp:142:96: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onShowInte
    rstitial(jstring)':
    jni/chartboost/gchartboost.cpp:154:3: error: 'gevent_createEventStruct1' was not
     declared in this scope
    jni/chartboost/gchartboost.cpp:158:92: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    jni/chartboost/gchartboost.cpp: In member function 'void GChartBoost::onShowMore
    Apps()':
    jni/chartboost/gchartboost.cpp:163:88: error: 'gevent_enqueueEvent' was not decl
    ared in this scope
    make: *** [obj/local/armeabi/objs/chartboost/chartboost/gchartboost.o] Error 1
     
    d:\coding\eclipse\Gideros\TestPlugin>
    Coming soon
  • fxonefxone Member
    edited March 2013
    @vitalitymobile do you have the same error after adding new files (Android.mk etc) under eclipse as earlier?
Sign In or Register to comment.