Here is the basic AdMob plugin implementation that works with Unity 3.2
Please give it a try and share your experience.
496428–17502–$AdMobTest.unitypackage (174 KB)
Here is the basic AdMob plugin implementation that works with Unity 3.2
Please give it a try and share your experience.
496428–17502–$AdMobTest.unitypackage (174 KB)
Cool. I’ll be trying this tonight along with the 3.2 OpenFeint Plugin.
I imported the package and ran on my droid and got a force close. I’m not seeing anything relevant in the logs so I’m a bit lost. I’m also not sure how to implement this from the get go. I looked through all the included files and didn’t see anything that points to a specific admob account. Any direction is greatly appreciated.
Edit: I solved my issue and got this working, see my last post below.
OK I attached the debugger and got the stack trace:
E/AndroidRuntime(17925): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.oyo.FanBoyLite/com.oyo.FanBoyLite.AdMobTestActivity}: java.lang.ClassNotFoundException: com.oyo.FanBoyLite.AdMobTestActivity in loader dalvik.system.PathClassLoader[/data/app/com.oyo.FanBoyLite-1.apk]
E/AndroidRuntime(17925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
E/AndroidRuntime(17925): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(17925): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(17925): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(17925): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17925): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(17925): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(17925): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17925): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(17925): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime(17925): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime(17925): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(17925): Caused by: java.lang.ClassNotFoundException: com.oyo.FanBoyLite.AdMobTestActivity in loader dalvik.system.PathClassLoader[/data/app/com.oyo.FanBoyLite-1.apk]
E/AndroidRuntime(17925): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime(17925): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(17925): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(17925): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(17925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
E/AndroidRuntime(17925): … 11 more
I know that class is in the plugin so I’m not sure why it can’t find it.
The example package works if run in its own project. I believe the problem is that my package name is com.oyo.FanBoyLite, where the example plugin uses org.example.AdMobTest . I am currently researching how to change the package name and rebuild. I’ll report my results here.
I tried importing the plugin into eclipse and renaming the package. Still getting the same error.
Just tried adding the classes.jar and admobsdk.jar to my build path in eclipse and cleaned my project. STILL getting the classnotfound exception.
did you try changing package org.example.AdMobTest; at AdMobTestActivity.java and package=“org.example.AdMobTest” at AndroidManifest.xml to com.oyo.FanBoyLite?
Yes. My initial problem was in the manifest file. Now I have copied my projects manifest file and attempted to add the admob activity to it:
<?xml version="1.0" encoding="utf-8"?>
android:configChanges=“orientation|keyboardHidden”
android:theme=“@android:style/Theme.NoTitleBar”
android:screenOrientation=“landscape”/>
The game runs without crashing now. But I don’t see anything indicating that the admob activity is running. There are no ads and nothing in logcat that indicates that it is running. Obviously I did replace the publisher ID with my publisher ID.
OK, after changing all occurrences of the package name to my package name, I was still getting the class not found exception…BUT…at some point I had changed the package name in Player Settings to try test some things out. When I changed it back I changed it to com.oyo.FanBoyLIte…note the capital “i”. Changing this to com.oyo.FanBoyLite fixed! I’ve never been so excited to see an ad in my life haha. I’ll post my final manifest file below just for clarification.
THANKS!
<?xml version="1.0" encoding="utf-8"?>
Has anyone integrated this with OpenFeint at the same time?
I know its possible. I think you have to combine this with the OpenFeintFacade example. In the OpenFeintFacade example, activities are called from C#, so theoretically you could extend the main activity for admob, then call openfeint activities using the Facade.
Look at my manifest.xml in the post above, I’m already extending the main activity to use the admobtest activity, so you could paste the contents of the openfeintfacade manifest below that and it should work. Hopefully I’ll be able to try it out tonight and I’ll let you know how it goes.
That would be great, thank you
BTW add this line to your admobtestactivity.java in org/example/admobtest to place your ads at the bottom of the screen:
layout.setGravity(android.view.Gravity.BOTTOM);
you’ll need to cd to your Plugins/Android directory and run “ant create-jar” to rebuild the plugin. If the build is successful you can hit build and run in unity and it should run on your device.
OK It worked.
First copy your project directory in case something bad happens (I had an unrecoverable crash when trying to import assets)
next open your project with admob installed.
drag/drop all the files from the openfeintfacade EXCEPT for androidmanifest.xml into your projects plugin dir
copy the OF activities into your existing androidmanifest.xml
Build>Run.
I logged into OF successfully and Admob was called, though the ad failed. But that means that the class got called so thats really all that matters.
Heres what your android manifest.xml should look like:
<?xml version="1.0" encoding="utf-8"?>
Wow, thank you very much buddy, you just made my day
Regards
One note here:
I just tried to change my admobtestactivity.jar and ran ant create-jar. When I tried to build and run i got an error saying “building dex failed”. I couldn’t figure it out so what I did was go back to my project that just had admob (no openfeint) and made the change there and ran ant create-jar, then integrated openfeint again. This worked perfectly.
I realize that this isn’t an ideal fix if you are going to change your admobtestactivity.jar a lot, but I don’t plan to.
I am going through all the steps I found here. I changed the package in the AdMobTestActivity.java file and I changed the package in AndroidManifest.xml,
Do I have to change the jar file to read my-package.jar instead of org.example.AdMobTest.jar, I changed that to be my-package.jar and I changed the structure of the filders in the bin/classes to com/my-company/my-productName
and also change the folder structure in src to com/my-company/my-productName so the AdMobTestActivity.java file is in that structure.
I can’t get it to work, my device always force closes, and I check the log cat and its still giving me that ClassNotFoundException in the logcat.
Anything else I can check? Or is there any other place I have to change names of folders, files, or instances in files??
@Christo : Can you make a video tutorial? I think many of us may need that
Thanks
Edit #3
Ok.
Reason the package by itself doesnt display any ads is it looks like the manifest needs this line:
Tyvm christo.
What I’ve done to get it working in my own project, is first add it to my project.
Let it build and crash on the android.
Went to my project’s temp folder, copied out the Staging folder.
Moved this to another area completely.
Made a new project in Eclipse based on the Relocated Staging folder.
Fixed all of the org.exmaple.AdMobTest calls.
Fixed the references to Jar library files (Was pointing to an utterly different folder for Unity than what I have on x64 windows)
C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androidplayer\bin
Made sure to include the admob-sdk-android.jar file as a library.
NOTE:
This looks to be an older admob library, which I am guessing is where the edits were done Wozik, as the AdMobTestActivity class is in there along with a bunch of other things, that is not in the current admob library, GoogleAdMobAdsSDK-4.0.2.jar
So good thing that was put together.
There were a few minor fixes here and there with things to get it to generate AdMobTestActivity correctly. But its done and working now.
I will now be attempting to convert this back to plug-in status for my project.
Thanks.
Edit #4
Well, Day 3. I dont even know what I did, I literally changed nothing, even restorted the AdMobTestActivity project in Eclipse that was working. Now its Force Closing again and its nearly impossible to figure out why.
Ive tried LogCat.
Ive tried debugging mode with Eclipse, which only makes a mess of things and doesnt tell me what is going on.
I am dumbfounded that it is this complex to get ads to work, let alone incorporate an external java library with Unity. It appears to be extremely sensitive and if a butterfly flutters in the wrong direction, everything goes nuts and explodes.
Edit #5
Haha Oops. Eclipse no likey if you replace files outside of eclipse or rename files.