Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Admob Unity Package that work with Unity 3.2, 3.3, 3.4 3.5

Discussion in 'Android' started by MicroEyes_old, Mar 16, 2012.

?

Are you Satisfy with this tutorial?

  1. Yes

    71.4%
  2. No

    9.5%
  3. Not Completely

    19.0%
  1. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    A NEW INDEPENDENT PLUGIN WITH NEW FEATURES..

    Hi Guys, After putting a lots of effort on Admob integration with Unity, i have something for you all.

    Please Read full tutorial before start. might you miss some important points. Good Luck

    Now its not just basic, i advanced it to some more control over Admob.

    NEW FEATURES;

    1. Make Adv visible or invisible anytime.
    2. Completely Disable Adv programatically.
    3. Perform 4 Animations on AdView container so that they appear or disappear smoothly.



    Here is the basic AdMob package implementation that works with almost every Unity Version greater den(i tested on 3.2, 3.3, 3,4 3.5)
    The older method, i found in Unity Forums is no more working hav some issue with ANT Android SDK version eclipse.


    What you need to implement??:
    JUST Unity with android SDK

    Direction of Using Admob Plugin.
    Class AdvertisementHandler.cs contains functions that you can call from anywhere in your Unity Project bcoz its a static class.

    Now, lets take a trip of features in this class to control Admob plugin.
    1. Instantiate: Call this function only once in life of unity project run. This function will instantiate all variables in plugin. This function have some arguments:
    • 1. Your Admob PublisherIdD.
    • 2. Advertisement Size: You can choose your advertisement Size or Let the plugin handle(Recommended). Please choose anyone from AdvSize enum
    • 3. advOrient: Gives you control over Advertisement Orientation. Please choose anyone from AdvOrientation enum
    • 4. Position 1 Position 2: Its a combination of two direction where you want Advertisement to display. Please choose anyone from Position enum
    • 5. isTesting: Its a boolean variable. Set this to true, if your are testing your unity game. This will affect your eCPM
    • 6. animIn: Animation for Advertisement container, when application receive Advertisement. Please choose anyone from AnimationInType enum. Use NO_ANIMATION for No Animation.
    • 7. animOut: Animation for Advertisement container, when application receive Advertisement old container need to go. Please choose anyone from AnimationOutType enum. Use NO_ANIMATION for No Animation.
    • . levelOfDebug: Define Level of debud log in device LogCat here. None: you wont get any log from admob plugin, LOW: you will get minimal required logs, HIGH: You will get flood of logs in your device logcat.

    2. EnableAds(): Call this to enable Ads.

    3. DisableAds(): Call this to disable Ads. Use EnableAds() to regain Advertisements.

    4. HideAds(): This will Hide Advertisement temporarily. Use ShowAds() to make Adv visible again.


    See "AdvertisementManager.cs" for more detail of how to control Admob Plugin.

    Attach "AdvertisementManager.cs" on a game object to make it run.

    NOTE: 'AdvertisementHandler.cs" is a static class, so use above functions like "AdvertisementHandler.EnableAds()" without creating any object of class.

    I Have Attached Two 7z file:
    1. AdmobUnityPackage.7z: This contains only file for your project.
    2. AdmobProject.7z: Contains a complete test project.


    IMPORTANT:
    If you are planning to use with another plugin, then in AndroidManifest.xml change value key in below line to True. By default its set to False
    <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" /> .


    If nothing happens on Adv click, then use above changes in AndroidManifest.xml



    If you get any issue plz share with me with full log from plugin. :D:D

    UPDATED TO LATEST ADMOB SDK 6.0.1

    HAPPY GAMING..

    Thankx for using this plugin..
     

    Attached Files:

    Last edited: Aug 5, 2012
  2. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    121
    Amazing post. And glad someone finally did it. I was going to make one but then I took a game to the knee. So busy=X lol anyway thanks mate
     
  3. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    In your service...... @joelsantos..
     
  4. ffff1111

    ffff1111

    Joined:
    Mar 18, 2012
    Posts:
    6
    WOW!,Thanks a lot for this tutorial!

    I have completed all the steps correctly without getting errors, but I can't receive ads.
    Is there any posibility to adapt the AdMobTestActivity.java to the new AdMob SDK 4.3.1?
    I think that that is my problem.
     
  5. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Yes ffff1111,
    I wrote this tutorial for ADmob package that is embeded in unityPackage... i haven't tried with new AdmobSDK...
    Please use AdmobPackage in SDK to get ur game workng..
     
    Last edited: Mar 20, 2012
  6. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    Thanks for sharing.
     
  7. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    There was a guy on the forum who tried with the new admob sdk in the android skd extras folder, but what I don't like of these "plug-in" approach is the fact that you extend the UnityPlayerClass, this works, but is wrong.

    Especially when you link against common JARs or the Android SDK itself.

    I'm trying to get a different version of the plug-in, with no java-compile, and no UnityPlayer extension.

    I hope I'll be able to do it.

    As far as I know Prime31 did it, but 40$ are too much to don't give a try first !
    If I succeed I will sell this plug-in for 20$.
     
  8. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Litobyte Softworks,
    Unity Engine gives us power to access Native code from Unity itself using AndroidJNI. Can you tell me, Why is this Wrong?

    You can refer these pages Here Here.

    Wat i wrote is based on unity tutorials its Free, Easy to use Customize.

    And this is my first try with plugins.
     
  9. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    I am terribly sorry MicroEyes, I didn't intend to attack or flame you in any way !
    I was just expressing my technical opinion on the matter.

    What do you think about an AdMob plugin, which compiles against the latest google.ad from the latest SDK (is retro compatible until minimum API=4!) which would be a simple .jar file and a .cs class to put in your plugin folder, then, without to do anything with 2 lines of code from anywhere you would set up the ad banner on screen ?

    You did a good job with JNI, but I don't use JNI call, but JavaClass.
    And I don't extend the UnityPlayer so, no subclassing, is lightweight, and to the point.



    I will post some update soon.


    The plug-in is there, it plays great with OpenFeintFacade together with our "force feedback" plug-in.

    Two files, 2 lines of code to get the ad on screen.

    Time to pack it!
     
    Last edited: Mar 23, 2012
  10. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    i followed the tuto , and apk is force closing in device and emulator .
    can u explain me about this line
    Line 108: adView.setKeywords(Add keywords as string); in the java file .

    would you upload a complete project files including a empty scene .
     
  11. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    kiranmaya,
    i'll upload my test project. Can you send me ur android log after crash..
     
  12. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    i deleted everything at present,will try once again.
     
  13. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    I have attached my "AdMob" test project.
     
  14. roxxy

    roxxy

    Joined:
    Mar 24, 2012
    Posts:
    2
    project is working well,
    but if I change id and add the library
    advertising in the scene do not have,
    changing back your id - ad works again
    that I could forget?
     
  15. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    roxxy,
    According to me, the problem is with your Admob account. please check it properly, whether you add the ID highlighted in image..

     
  16. roxxy

    roxxy

    Joined:
    Mar 24, 2012
    Posts:
    2
    new Admob id not work with old sdk=(
    AdMob SDK Update
    All new Android, iPad, iPhone, and Windows Phone 7 apps require an AdMob SDK that was released on or after March 15, 2011.

    If you are using a version of the AdMob SDK that was released before March 15, 2011, then your new app will not receive any ad impressions.
     
  17. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Roger That...I'll update my tutorial asap... :D
     
  18. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    my old game id ,com.marketingstreams.arunner ,which was was registered in admob around march 2011 is working and geting ads ,
    but newly created id (a week back ),com.acegames.raceCar is not receiving ads .
     
  19. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Of course Kiranmaya, according to new google admob guidelines, after october 2011 you HAVE to use the newest adMobGoogle.jar version 4.0.1 or newer.

    We have just baked a no-java-compile no-headscracth plugin for the new adMob, if interested drop me a line or a PM,

    Tom
     
  20. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Thankx kiranmaya for your precious Feedback.

    Guyz, I have updated my Admob Tutorial to Latest Admob SDK 4.3.1 and uploaded new unitypackage a working Test Project with screen output..
     
  21. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    New Tutorial available with Latest Admob SDK 4.3.1.
     
  22. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Litobyte Softworks,
    Donot open your market here. Its a free tutorial. I am doing what i can do my best.
    Open your Stall somewhere else sell your things..
     
  23. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    my new created publisher id is also working flawlessly.

    Thanks Satbir Singh
     
  24. Somedays

    Somedays

    Joined:
    Jan 2, 2012
    Posts:
    214
    Do I have to have Unity Pro to use plugins? or Unity Pro AND Android Pro?
     
  25. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    SomeDays,
    No you don't need Unity Pro to use this plugin.. Unity Pro is needed for pre-compliled plugins like *.DLL or android NDK. This plugin is complied by you create JAR plugin from it. It will work with normal Unity.
     
  26. Somedays

    Somedays

    Joined:
    Jan 2, 2012
    Posts:
    214
    OH ok thanks for clarifying.
     
  27. Zoo

    Zoo

    Joined:
    Apr 2, 2012
    Posts:
    4
    Hello.
    I`m new in Unity3d and Eclipse software. When i open AdmobTestActivity.java in eclipse, i had a errors on @Override - The method onDismissScreen(Ad) of type AdmobTestActivity must override a superclass. I`m delete this Overrides, export AdmobTestActivity.jar file.
    When Ads start showing normal, but when i try to use HideAds(), ShowAds() and other Ads function, my app got crash.

    Sorry for bad English.
     
  28. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Hi Zoo,
    onDismissScreen() is an event in AdListener in Google Admob SDK.
    It is called when an ad is clicked and about to return to the application.
    Solution 1: Please make sure that you are using Google Admob SDK comes with this tutorial. If not please use this latest Admob sdk.

    Solution 2: Check your "AdvertisementManager.cs", change "org/test/admob/AdMobTestActivity" to "your_package/AdMobTestActivity" set.. Do this in all four functions. use "/"(forward slash) instead of "."(Dot). Here "AdMobTestActivity" is java file name. (your_package is bundle identifier you set in Player Setting for Android.)

    If still you are unable to run, please post your android log here or pm me.

    I'll reply you asap. B-)
     
  29. Zoo

    Zoo

    Joined:
    Apr 2, 2012
    Posts:
    4
    maybe the problem in Eclipse version? I`m using Eclipse SDK Version: 3.7.2
     
  30. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    I am working with Eclipse IDE for Java Developers Version: Helios Service Release 2
     
  31. Zoo

    Zoo

    Joined:
    Apr 2, 2012
    Posts:
    4
    Thanks for help, try to use it )
     
  32. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    No problem Zoo. Any time In your service.. B-)
     
  33. GameFreak

    GameFreak

    Joined:
    Oct 31, 2011
    Posts:
    13
    Hi.

    I am working on Mac,

    how do i import the android folder?
    I did Eclipse--> Import --> File system --> then directory of my project till the android folder

    However it shows many many errors
    Further there is no classes.jar in my system.
     
  34. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    GameFreak,
    1. Right click on Project in Eclipse -> properties.
    2. Select "Java Build Path". Remove "classes.jar"(if any one there).
    3. Click on "Add external Jar" and mount "your_unity_path\Unity\Editor\Data\PlaybackEngines\androiddevelopmentplayer\bin\classes.jar"

    it will add Unity Classes to your project.. If you still get any error plz post here. I'll try to solve.
     
  35. GameFreak

    GameFreak

    Joined:
    Oct 31, 2011
    Posts:
    13
    I imported classes.jar you provided in the sample project because classes.jar is not there on my system.

    Still 5 errors:

    Description Resource Path Location Type
    The method onDismissScreen(Ad) of type AdmobTestActivity must override a superclass method AdmobTestActivity.java /a/src/org/admob/test line 146 Java Problem


    Description Resource Path Location Type
    The method onFailedToReceiveAd(Ad, AdRequest.ErrorCode) of type AdmobTestActivity must override a superclass method AdmobTestActivity.java /a/src/org/admob/test line 131 Java Problem

    Description Resource Path Location Type
    The method onLeaveApplication(Ad) of type AdmobTestActivity must override a superclass method AdmobTestActivity.java /a/src/org/admob/test line 156 Java Problem

    Description Resource Path Location Type
    The method onLeaveApplication(Ad) of type AdmobTestActivity must override a superclass method AdmobTestActivity.java /a/src/org/admob/test line 156 Java Problem

    Description Resource Path Location Type
    The method onReceiveAd(Ad) of type AdmobTestActivity must override a superclass method AdmobTestActivity.java /a/src/org/admob/test line 124 Java Problem
     
  36. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    GameFreak,
    These errors are not related to "classes.jar", these are related to Google Admob jar file. Please import latest admob package into your project.

    One more thing, please check have u implemented "AdListener" in your Activity. In my case, it is
    public class AdMobTestActivity extends UnityPlayerActivity implements AdListener
    {
    /// your code.
    }
     
  37. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
  38. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Wow kiranmaya,
    Lots of Congrates for yout Game.
    I have downloaded it. its really a good game.i'll play on my device.
     
  39. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    Thanks Satbir Singh.

    right now im using Qualcomm AR-Image Targets ,to do augment reality destroyer game .
    check this link for gameplay .
    http://www.youtube.com/watch?v=5wycy5dTYnM.
    Ar package comes with another manifest ,and i have merged admob's package manifest to this manifest .
    Code (csharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.AceGames.DestroyerAR"
    5.     android:versionCode="1"
    6.     android:versionName="1.0">
    7.     <uses-sdk android:minSdkVersion="7" />
    8.     <uses-feature android:name="android.hardware.camera" />
    9.     <supports-screens
    10.         android:smallScreens="true"
    11.         android:normalScreens="true"
    12.         android:largeScreens="true"
    13.         android:anyDensity="true" />
    14.     <uses-permission android:name="android.permission.WAKE_LOCK" />
    15.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    16.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    17.     <uses-permission android:name="android.permission.INTERNET" />
    18.     <uses-permission android:name="android.permission.CAMERA" />
    19.     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    20.    
    21.     <application
    22.         android:icon="@drawable/ic_launcher"
    23.         android:label="@string/app_name"
    24.         android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    25.         >
    26.        <activity
    27.             android:label="@string/app_name"
    28.             android:name=".AdmobTestActivity" >
    29.             <intent-filter >
    30.                 <action android:name="android.intent.action.MAIN" />
    31.  
    32.                 <category android:name="android.intent.category.LAUNCHER" />
    33.             </intent-filter>
    34.         </activity>
    35.         <activity android:name="com.google.ads.AdActivity"
    36.              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >            
    37.         </activity>
    38.        
    39.             <activity android:name="com.qualcomm.QCARUnityPlayer.QCARPlayerProxyActivity"
    40.                   android:label="@string/app_name"
    41.                   android:configChanges="keyboard|keyboardHidden|orientation">
    42.            
    43.         </activity>
    44.         <activity android:name="com.qualcomm.QCARUnityPlayer.QCARPlayerActivity"
    45.                   android:label="@string/app_name"
    46.                   android:configChanges="keyboard|keyboardHidden|orientation">
    47.         </activity>
    48.         <activity android:name="com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity"
    49.                   android:label="@string/app_name"
    50.                   android:configChanges="keyboard|keyboardHidden|orientation">
    51.             <meta-data android:name="android.app.lib_name" android:value="unity" />
    52.         </activity>
    53.         <activity android:name="com.unity3d.player.VideoPlayer"
    54.                   android:label="@string/app_name"
    55.                   android:configChanges="keyboard|keyboardHidden|orientation">
    56.         </activity>
    57.        
    58.        
    59.     </application>
    60. </manifest>
    61.  
    62. <!-- android:installLocation="preferExternal" -->
    with this manifest only admob is working , if i put intent-filter to "com.qualcomm.QCARUnityPlayer.QCARPlayerProxyActivity" activity in xml,AR is working and admob is not launching,
    Code (csharp):
    1. <intent-filter>
    2.                 <action android:name="android.intent.action.MAIN" />
    3.                 <category android:name="android.intent.category.LAUNCHER" />
    4.             </intent-filter>
    how to launch both AR pluging and admob at same time?
     
  40. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    kiranmaya,
    Have you tried calling SetupAds() function in AdmobTestActivity?
     
  41. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    nope,how to call that function ?
    so it is not about launching the activity with manifiest xml
     
  42. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    kiranmaya,
    There is function in AdMobTestActivity.java called "SetupAdvs()" you can call this function to manually enable your advertisements in unity.,
    You can call this function from unity using AdvertisementManager.cs embeded in my AdmobTest.unityPackage.
     
  43. kiranmaya

    kiranmaya

    Joined:
    May 27, 2010
    Posts:
    218
    @mirctoeyes.

    the problem is not enable and disable the ads,
    i want to launch the AR pluging along with admobtest activity .as of now ,im able to get either ads or AR at once ,not both at same.
     
  44. kalm

    kalm

    Joined:
    Apr 6, 2012
    Posts:
    7
    Hi MicroEyes,

    Thanks for the great tutorial but I've missed something somewhere, I'm getting a compile error at step 9 and the application gets a Force Close on my device.

    It could be that on step 5 (renaming the package) there was already a package listed with my package name so I used a slightly different package name for the org.test.admob package.

    I'm guessing that I must have imported the Android folder wrong to have this duplicate package name in Eclipse but I'm not used to Eclipse so not 100% sure here.

    Any ideas what I've done wrong?

    Kalm
     
  45. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    kiranmaya,
    Then in this case, you need to create a thread of SetupAdvs() function. Can you tell, how you are calling SetupAdvs() function from your function. Is this from a cs file?

    And how you are calling AR plugin,? bcoz i havn't work with AR, thats y i have no idea abut How AR is working...
     
  46. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188

    Hi kalm,
    in Eclipse its very easy to rename a package name. Just click on package on "Project Explorer" in Eclipse. RIght click on it rename to whatever you want. also don't forget to rename package name in AdvertisementHandler.cs in Unity. keep this in mind, the package name should b the package name used in Unity's Build Setting
     
  47. kalm

    kalm

    Joined:
    Apr 6, 2012
    Posts:
    7
    MicroEyes,

    Thanks buddy,

    With your help from the PM and re-reading the thread I was able to track down the issue with the force close.

    It was due to the @Override

    Eclipse suggested I remove the @override which allowed the jar to compile.

    I hope this makes sense.

    Thanks again for all of your help and for making this great plugin.

    Kalm
     
  48. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    In your Service Kalm,
    I hope you learned some Android with Unity.. :D
     
  49. kalm

    kalm

    Joined:
    Apr 6, 2012
    Posts:
    7
    It was going so well.

    Now I don't seem to be able to switch the ads off with AdvertisementManager.HideAds() or DisableAds()

    Calls to these functions appear to make the app lock up and then Force Close.

    It would also be useful to be able to reposition the ads, do you know if that's possible?

    Kalm
     
  50. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    HI KALM,
    Dude, DIsableAds() are not working obslete. But HideAds() is perfectly working on my side. you shud probably check your android log or PM me your log. so i can debug..

    About repositioning, you can reposition your adv but you have to re-create your linear layout with different gravity. Gimme some tym i'll re work on repositioning thing.