Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
adPlugin for android — Gideros Forum

adPlugin for android

hgvyas123hgvyas123 Guru
edited August 2012 in Plugins
hi guys i have tried my hand on plugin and objc and integrated three ad network

admob (only banner ad of the size of 320x50 other ads can be taken by changing the java code)
leadbolt (appwall and Interstitial ad)

thanks to @scouser for solving the crash issue.

project :-

https://docs.google.com/open?id=0B7iwHFSez0W8NlMxRk92ODZ2dE0

uasage :-
 
require "myAdMob"
require "myLeadBolt"
require "myWebView"
 
local function handleEvent(self,event)
	if self:hitTestPoint(event.x,event.y) then
		if self.myName == "hideAd" then
			myAdMob.hideAd()
		elseif self.myName == "showAd" then
			myAdMob.showAd()
		elseif self.myName == "changePos" then
			myAdMob.changeAdPos(0,math.random(480))
		elseif self.myName == "leadBoltInterstitial" then
			myLeadBolt.loadAd("202260852")
		elseif self.myName == "leadBoltAppWall" then
			myWebView.load("<a href="http://ad.leadboltads.net/show_app_wall?section_id=766169778&quot" rel="nofollow">http://ad.leadboltads.net/show_app_wall?section_id=766169778&quot</a><img class="emoji" src="https://forum.giderosmobile.com/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
 
		end
	end
end
 
local hideAd = TextField.new(myFont,"hideAd")
hideAd.myName = "hideAd"
stage:addChild(hideAd)
 
local showAd = TextField.new(myFont,"showAd")
showAd.myName = "showAd"
stage:addChild(showAd)
 
local changePosAd = TextField.new(myFont,"changePos")
changePosAd.myName = "changePos"
stage:addChild(changePosAd)
 
local leadBoltBanner = TextField.new(myFont,"leadBoltInterstitial")
leadBoltBanner.myName = "leadBoltInterstitial"
stage:addChild(leadBoltBanner)
 
local leadBoltAppWall = TextField.new(myFont,"leadBoltAppWall")
leadBoltAppWall.myName = "leadBoltAppWall"
stage:addChild(leadBoltAppWall)
 
for i=1,stage:getNumChildren() do
	local sprite = stage:getChildAt(i)
	if sprite.myName ~= nil then
		sprite:setPosition(0,50+i*50)
		sprite:addEventListener(Event.MOUSE_DOWN, handleEvent,sprite)
	end
end
 
myAdMob.loadAd("youradmobid")--must be called only once otherwise two or more ads will be there

Likes: jenotscom, fxone

Tagged:
+1 -1 (+2 / -0 )Share on Facebook

Comments

  • forgot to say if you are going to try leadbolt plz register from

    http://www.leadbolt.com/developers_signup.php?ref=10029307

    also for app icon ad and notification ad there is no need of plugin

    thnx
  • Wow, that's awesome. Thank you, will definitely try it out ;)
  • gorkemgorkem Maintainer
    @hgvyas123 is it possible that you upload the sample doc to Github? It's too hard to understand how to download / investigate files on Google docs.

    Likes: Disciple

    +1 -1 (+1 / -0 )Share on Facebook
  • @hgvyas123 i wrote you before about android support for your previous plugin for Ios only. What can i say you rock:D Thanks for the android version really. It will be unbeleivable handy for me. Thanks again.
  • talistalis Guru
    edited August 2012
    Edit: Ok neglect the question i found that you used their SDK:) Sorry google code is really not so user friendly as Github. I should have to get used to it:D

    @hgvyas123 I have one question regarding this plug-in. Did you used google's sdk for Admob or are you calling by a http request like ad-sense? (Admob sdk jar file)
  • sorry for late reply but as usual i was away and i had tried to move it to the github but i failed some one can tell me how to do that or move it on github.

    thnx :)
  • Hello,
    can anyone share on how to use this plugin? Implementing ads is the last step left before realesing the app. Mostly interested in AdMob.

    Some (maybe stupid) questions:

    1) Do I need to simply copy some dll to some folder or modify exported android project to implement that?

    Because when I view MyAdMob.java, it include calls to ElasticJointsActivity, which relates to ElasticJoints app. So obviously I'll need to rewrite it to match my app. Or there any universal way to do this?

    2) To test it, does it work only on exported android project, or it can work in Gideros player too?

    Steps I need to do:
    1) include Admob SDK into project
    2) copy MyAdMob.cpp into jni directory
    3) copy libmyAdMob.so into libs directory for both armeabi
    4) rewrite MyAdMob.java to match my app's activity and include into src/com/giderosmobile/android

    Or is there any better way to do it before exporting app, so it would be done automatically? Or did I miss anything?

    Completely confused now. Any help appreaciated.


    Dislikes: FrancoisDM

    +1 -1 (+0 / -1 )Share on Facebook
  • @jenotscom

    i had not tried it with giderosplayer but it will work.

    here's the what i am doing

    copy the .so files from libs folder (myAdmob.so and myLeadbolt.so) in ur folders armeabi-v7a and armeabi respectively. do not replace any .so file.

    copy jar files and add them to build path

    copy java files from src directory

    replace ElasticJointsActivity with ur activity or class name in all three java files

    some of the changes also needed in ur activity match both and u r ready

    no need to take .cpp or .mk file unless u want to add other functions. let me know if it not work.

    :)
  • My main problem basically is, that if I use lua to manipulate AdMob, basically if I use this example code:
    require "myAdMob"
    myAdMob.loadAd("youradmobid")
    myAdMob.changeAdPos(0, 480)
    myAdMob.showAd()
    I can't run my app anymore in Gideros Player, because, well myAdMob lib does not exist.

    So if I only save project (without running/compiling app), I then can not check if this project modification (AdMob manipulated lua code) even correctly exported. Because I can't find plain lua files in exported project to check it.

    And it's also can be quite a bit stressfull to test it like this, always exporting project.

    But I think I got the idea and will try to do it tonight. Only hoped there was a better way.

    Still thank you so much for sharing this ;)
  • ScouserScouser Guru
    edited August 2012
    @jenotscom: You could always try
    if application:getDeviceInfo() == "Android" then 
    require "myAdMob"
    myAdMob.loadAd("youradmobid")
    myAdMob.changeAdPos(0, 480)
    myAdMob.showAd()
    end
    This would then only try to show ads on an Android device
    +1 -1 (+3 / -0 )Share on Facebook
  • jenotscomjenotscom Member
    edited August 2012
  • I've been playing all day with the plugin, I'm not a professional with Android and Java, but the results where, that I firstly could not launch even provided example project (on Windows 7, Android 4.1 SDK). App simply crashed without any error in logcat (which I found quite curious).
    Then I decided to put contents of myAdMob.java methods into try and catch blocks, hoping to see an exception. And all suddenly seemed to start working. Tried to implement it on another bigger project as GameTemplate and even with try catch blocks got occasional crashes (again without specific errors, sometimes it's "Undefined type' ", sometimes simply "VM aborting", sometimes nothing).

    Sent same apk to my friend to test, and he told that he couldn't even launch the application no matter how many times he tried.

    When I comment out admob usage inside lua (haven't tried other ad networks), everything works fine.

    @hgvyas123 have you tested this plugin with latest Android SDK. Latest Gideros SDK. Maybe it's a windows Android SDK related problem? Does everything work fine for you?
  • hgvyas123hgvyas123 Guru
    edited August 2012
    @ar2rsawseen
    yup i had tested this on my device with latest gideros studio and i think so latest android sdk or may be in 4.0.3 (not sure)

    also see this thread
    http://www.giderosmobile.com/forum/discussion/1506/crash-on-android-java.lang.clonenotsupportedexception-class-doesn039t-implement-cloneable#Item_12

    at that time also in my device it is running perfectly but not in other device may be my device is the real smartphone i am guessing that it is related with the android os version installed on device i have icecream. as u can see from the above thread it is giving some strange errors on my friends devices and @scouser had solved that. may be need some more lights on this.

    by the way by finding this crash u have saved me from the big issue of github :D

    :)
  • Ok, the problem seems to be with JNI (probably somewhere in myAdMob.so). Because:
    1. there is no error message in LogCat
    2. LogMessages aren't outputted from myAdMob.java (meaning java class is not called at all)
    3. If calling admob functions are commented out inside myAdMob.java it still crashes.

    Problem persists on Android 2.2 where you can't even start the app (it always crashes) and on Android 2.3 it works almost all of the time, only sometimes crashing.

    So problem probably is with calling Java methods using JNI. Did someone managed to do it that it would work on all android versions? That would help a lot. :)

    and @hgvyas123 when it's fixed, you're back to your github issue ;) :D
  • Hello all,
    just an update, I've been dissecting this plugin bit by bit, trying to reconstruct it from scratch etc (Which will probably turn into a nice Android plugin development tutorial if I manage to get it working correctly :) ).
    And now I almost certainly know what is wrong, just don't know how to fix it.

    So for example if we take this c++ function using JNI:
    static int admobtest(lua_State *L)
    {
    	try
    	{
    	__android_log_print(ANDROID_LOG_DEBUG, "blah", "admobtest1");
    	if(ENV == NULL) return 0;
    	__android_log_print(ANDROID_LOG_DEBUG, "blah", "admobtest2");
     
    	jclass cls = ENV->FindClass("com/giderosmobile/android/AdMob");
    	if(!cls) return 0;
    	__android_log_print(ANDROID_LOG_DEBUG, "blah", "admobtest3");
     
    	jmethodID method = ENV->GetStaticMethodID(cls, "loadAd", "(Ljava/lang/String;)V");
    	if(!method) return 0;
     
    	__android_log_print(ANDROID_LOG_DEBUG, "blah", "admobtest4");
     
    	const char somevalue[] = "bhahahaha";
     
    	ENV->CallStaticVoidMethod(cls, method, ENV->NewStringUTF(somevalue));
     
    	lua_pushnumber(L, 123123);
    	__android_log_print(ANDROID_LOG_DEBUG, "blah", "admobtest5");
    	return 1;
    	}
    	catch(...)
    	{
    		__android_log_print(ANDROID_LOG_DEBUG, "blah", "failed");
    		return 0;
    	}
    }
    Then since lui is running on a separate thread, to get back on UI thread I tried to create a handler in main activity and then use it from Admob activity like this:
    public class AdMob {
    	public static void loadAd(String somevalue){
    		Log.d("blah", "blah blah" + somevalue);
     
    		Runnable runnable = new Runnable() {
     
    			<a href="https://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    			public void run() {
    				Log.d("blah", "blah blah - 2");
    			}
    		};
    		Log.d("blah", "blah blah - 1");
     
    		try
    		{
    			BitOpActivity.han.post(runnable);
    		}
    		catch(Exception ex)
    		{
    			Log.d("blah", ex.toString());
    		}
     
    		Log.d("blah", "blah blah - 3");
    	}
    }
    I get output on console:
    admobtest1
    admobtest2
    admobtest3
    admobtest4
    blah blah - 1
    blah blah - 2

    and it crashes. No exception, nothing. Basically if I don't use runnable (don't try to run anything on UI thread, it all works perfectly, passing values, returning values, etc). So question is, how should I properly run something on UI thread to display admob view? Is there any other way?
    For now issue is only with Android 2.2 (never works) and Android 2.3 (sometimes works)

    Likes: hgvyas123

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.