Search Unity

  1. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

AdMob plugin that works in Unity 3.2

Discussion in 'Android' started by Wozik, Feb 11, 2011.

  1. a28306

    a28306

    Joined:
    Sep 28, 2011
    Posts:
    11
    To MicroEyes:
    It's very kindness of you help me so much.
    these are my java project's directory structure,all the files in it are copy from the AdMob.and i modify the package name,then re-build it.


    I use "jar cvf com.jytx.game.jar com\" command making the bin\com\ fold in the java project to a jar package.cope it to the lib fold in the Unity project.
    this is my Unity project's directory structure.

    my problem is
    i build and run my Unity project on Device.
    if choose "ARMv6" in Device filter of player settings,the game launchs but shuts down in a quick time.
    if choose "Emulator",the game runs successfully.the ads show up.
    so if you need anything else i have can help you to solve the problem,please tell me.
    thank you very much!

    Plz open the pictures in new Tabs
     
    Last edited: Oct 17, 2011
  2. Zahel

    Zahel

    Joined:
    Sep 20, 2011
    Posts:
    43
    So, I'm trying to implement the C# script that syslord2k2 referenced on the second page of the thread, but anytime I call the Enable/DisbaleAds on an actual android device the game gets force closed.

    The code remains virtually unchanged from the original:
    Code (csharp):
    1.  
    2. public void EnableAds()
    3. {
    4.     AndroidJNI.AttachCurrentThread();
    5.  
    6.     // first we try to find our main activity..
    7.     IntPtr cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
    8.     IntPtr fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;");
    9.     IntPtr obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity);
    10.  
    11.     IntPtr cls_OurAppNameActivityClass = AndroidJNI.FindClass("com/SPS/FAD/AdMobTestActivity");
    12.     IntPtr startAdsMethod = AndroidJNI.GetMethodID(cls_OurAppNameActivityClass, "EnableAds", "()V");
    13.  
    14.     if (AndroidJNI.IsInstanceOf(obj_Activity, cls_OurAppNameActivityClass) != false)
    15.     {
    16.         jvalue[] myArray = new jvalue[1];
    17.         AndroidJNI.CallVoidMethod(obj_Activity, startAdsMethod,myArray);
    18.     }
    19. }
    20.  
     
  3. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    To Zahel,

    Plz try this on both Emulator Device.. check if still get the same problem.. if it runs fine on Emulator then u r having issue with java file..

    According to me, the problem was in java file...
    Plz... Upload ur "AdmobTestActivity.java" file.. or u can use mine... Download it from here:
    http://www.megaupload.com/?d=641PYVF0

    use can use;
    DisableAds(): To Completely Disable Advertisements on App startup or as u like..
    EnableAds(): To Enable Adv...
    HideAdv(): To hide Adv temporarily
    ShowAdv(): To Show Adv that is hide by HideAdv() function...


    If u still get any error plz share with me..
    And plz upload Log from ur Device too. it will help us in solution....

    Happy to Help.. :)
     
  4. Zahel

    Zahel

    Joined:
    Sep 20, 2011
    Posts:
    43
    That's what I was using, was yours, as you had recommended earlier, modified slightly for my game, and I was still having the problem, here is the java file that I'm currently using.

    Code (csharp):
    1.  
    2. package com.SPS.FAD;
    3.  
    4. import android.os.Bundle;
    5. import android.os.Handler;
    6. import android.util.Log;
    7. import android.view.View;
    8. import android.view.ViewGroup.LayoutParams;
    9. import android.widget.LinearLayout;
    10. import android.os.Message;
    11.  
    12. import com.unity3d.player.*;
    13.  
    14. import com.admob.android.ads.AdView;
    15. import com.admob.android.ads.SimpleAdListener;
    16. import com.admob.android.ads.AdManager;
    17.  
    18. import android.content.Context;
    19. import android.provider.Settings.Secure;
    20.  
    21. public class AdMobTestActivity extends UnityPlayerActivity
    22. {
    23.     public AdView adView;
    24.    
    25.     private boolean adVisible = true;
    26.  
    27.     protected void onCreate(Bundle savedInstanceState)
    28.     {
    29.         Log.i("AdMob", "onCreate");
    30.  
    31.         // super (UnityPlayerActivity) will use setContentView() ...
    32.         super.onCreate(savedInstanceState);
    33.  
    34.         // ... so instead of using setContentView(), we call addContentView() from setupAds()
    35.         setupAds();
    36.  
    37.         final String androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
    38.         Log.i("Admob", "Android ID: " + androidId);
    39.                        
    40.         // Add test devices (check the logcat for the ID string of your device..)
    41.         AdManager.setTestDevices( new String[] { androidId } );
    42.     }
    43.     private Handler handler = new Handler()
    44.     {
    45.         public void  handleMessage(Message msg)
    46.         {
    47.             switch (msg.what)
    48.             {
    49.                 case 0:     //Disable Adv
    50.                     if (adVisible)
    51.                     {
    52.                         adVisible = false;
    53.                     }
    54.                     break;
    55.                
    56.                 case 1:     //Enable Adv
    57.                     if (!adVisible)
    58.                     {
    59.                         adVisible = true;
    60.                     }
    61.                     break;
    62.                
    63.                 case 2:     //Enable but Hide Adv
    64.                         adView.setVisibility(View.GONE);                       
    65.                     break;
    66.                        
    67.                 case 3:     //Enable but Show Adv
    68.                         adView.setVisibility(View.VISIBLE);
    69.                     break;             
    70.                 default:
    71.                     break;
    72.             }
    73.         }
    74.     }; 
    75.  
    76.     public void DisableAds()
    77.     {
    78.         handler.sendEmptyMessage(0);
    79.         //adView.setVisibility(View.INVISIBLE );
    80.     }
    81.    
    82.     public void EnableAds()
    83.     {
    84.         handler.sendEmptyMessage(1);
    85.         //adView.setVisibility(View.VISIBLE );
    86.     }
    87.    
    88.     public void HideAdv()  //Enable Adv but Hide
    89.     {
    90.         handler.sendEmptyMessage(2);
    91.     }
    92.  
    93.     public void ShowAdv()  //Show Adv
    94.     {
    95.         handler.sendEmptyMessage(3);
    96.     }
    97.    
    98.     private void setupAds()
    99.     {
    100.         LinearLayout layout = new LinearLayout(this);
    101.         layout.setOrientation(LinearLayout.VERTICAL);
    102.         layout.setGravity(android.view.Gravity.TOP);   //To put AdMob Adv to Bottom of Screen      
    103.         addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    104.  
    105.         adView = new AdView(this);
    106.         layout.addView(adView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    107.  
    108.             adView.setBackgroundColor(0xff000000);
    109.             adView.setPrimaryTextColor(0xffffffff);
    110.             adView.setSecondaryTextColor(0xffcccccc);
    111.             adView.setKeywords("android game fire dice firefighter firefighting firetruck truck puzzle strategy luck fun");
    112.             adView.setRequestInterval(30);
    113.  
    114.         // add listener for easier debugging
    115.             adView.setAdListener( new SimpleAdListener()
    116.             {
    117.                 public void onFailedToReceiveAd(com.admob.android.ads.AdView adView)
    118.                 {
    119.                     Log.d("AdListener", "onFailedToReceiveAd: " + adView.toString());
    120.                     super.onFailedToReceiveAd(adView);
    121.                 }
    122.  
    123.                 public void onFailedToReceiveRefreshedAd(com.admob.android.ads.AdView adView)
    124.                 {
    125.                     Log.d("AdListener", "onFailedToReceiveRefreshedAd: " + adView.toString());
    126.                     super.onFailedToReceiveRefreshedAd(adView);
    127.                 }
    128.  
    129.                 public void onReceiveAd(com.admob.android.ads.AdView adView)
    130.                 {
    131.                     Log.d("AdListener", "onReceiveAd: " + adView.toString());
    132.                     super.onReceiveAd(adView);
    133.                 }
    134.  
    135.                 public void onReceiveRefreshedAd(com.admob.android.ads.AdView adView)
    136.                 {
    137.                     Log.d("AdListener", "onReceiveRefreshedAd: " + adView.toString());
    138.                     super.onReceiveRefreshedAd(adView);
    139.                 }
    140.             } );
    141.             adView.requestFreshAd();
    142.     }
    143. }
    144.  
     
  5. Need2Revolt

    Need2Revolt

    Joined:
    Sep 4, 2011
    Posts:
    19
    Hi everybody! Since i've seen this is a common problem in the unity community, i decided to make an asset that make it as easy as possible to integrate admob in unity games for android. The asset comes with detailed instructions on what you need to customize (basically it's just the publisher id, to link your admob account to your game and the position of the ad banner) and it's ready to be included in your game or works as a starting point if you haven't started to develop the game already.
    You can find it on the asset store for a ridiculously low launch price here: http://u3d.as/content/octopus-studios/google-ad-mob-for-unity-android
    Also, if you want to see it in action, this game uses it: https://market.android.com/details?id=net.octopusstudios.ARachnophobia
     
  6. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    To Zahel,
    Your Java file is ok.. Plz check to Inbox for detail.. :)
     
  7. syst3m

    syst3m

    Joined:
    Sep 17, 2011
    Posts:
    6
    Help Me!!

    ant create-jar

    and build failed

    Target "create-jar" does not exist in the project "AdMobTestActivity"
     
  8. Zahel

    Zahel

    Joined:
    Sep 20, 2011
    Posts:
    43
    @MicroEyes, check your inbox.
     
  9. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    To syst3m,
    "create-jar" is not present in "AdMobTestActivity.java" class. "create-jar" command is for ANT to create jar file. That file is "build.xml"....
    u need to setup ANT to create jar file or find some other way to create jar..
     
  10. Sunrift

    Sunrift

    Joined:
    Oct 13, 2011
    Posts:
    18
    When I type "./android update project ect..." I get the error: '.' is not recognized as an internal or external command, operable program or batch file.

    Am I making some simple mistake here?

    The same thing happens if I type "./android list targets"

    I am in "C:\AndroidSDK\tools>" when I try this.
     
  11. Need2Revolt

    Need2Revolt

    Joined:
    Sep 4, 2011
    Posts:
    19
    ./ is linux stuff, and you appear to be on windows... try using "android.exe update project etc..." instead, it should work...
     
  12. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    To Sunrift,

    If u r running Mac
    Solution 1: Please login with Admin privilieges. it will solve ur problem

    if u r running Windows
    Solution 1: "./android" is only runnable on Mac. './' is a Mac command to execute a program via command line.
    Plz use 'android list targets' (without quotes).. It will work.. if in case it doesn't proceed to next solution..

    Solution 2: Please install Android "platform-tools".... these r different from tools shipped with Android Package. This "platform-tools" has actual "adb.exe" "android.exe".

    Solution 3: Plz set ur Android "tools" and "platform-tools" in ur system PATH variable.

    If nothing works plz post here again or PM me..
     
  13. nshack31

    nshack31

    Joined:
    Nov 4, 2011
    Posts:
    96
    same here, did you find a solution?
     
    Last edited: Dec 12, 2011
  14. Mindunity

    Mindunity

    Joined:
    Dec 30, 2011
    Posts:
    22
    I tried to load this in unity, it saids failed to load, how can I use this?
     
  15. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    242
    Can anyone think of a way to rotate your own banner ads into this?
     
  16. ncst

    ncst

    Joined:
    May 28, 2011
    Posts:
    207
  17. syst3m

    syst3m

    Joined:
    Sep 17, 2011
    Posts:
    6
    no i dont find...

    where can I download this file >> SDK Tools, Revision 13 (September 2011)
    if i find this file, when i solving problem :(
     
  18. Topikc

    Topikc

    Joined:
    Jan 20, 2012
    Posts:
    2
    I have been trying to ANT create-jar but this is what I get, any idea why?


    BUILD FAILED

    \build.xml:46: taskdef class com.android.ant.SetupTask cannot be found using the classloader AntClassLoader[]
     
  19. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    242
    I used to be able to run the following with no errors:
    android.bat update project -t 2 -p c:\xxxxxx


    Now when I try to run it I get:

    Code (csharp):
    1.  
    2. build.xml: Failed to find version-tag string. File must be updated.
    3. In order to not erase potential customizations, the file will not be automatical
    4. ly regenerated.
    5. If no changes have been made to the file, delete it manually and run the command
    6.  again.
    7. If you have made customizations to the build process, the file must be manually
    8. updated.
    9. It is recommended to:
    10.         * Copy current file to a safe location.
    11.         * Delete original file.
    12.         * Run command again to generate a new file.
    13.         * Port customizations to the new file, by looking at the new rules file
    14.           located at <SDK>/tools/ant/build.xml
    15.         * Update file to contain
    16.               version-tag: custom
    17.           to prevent file from being rewritten automatically by the SDK tools.
    18.  
     
  20. sleglik

    sleglik

    Joined:
    Jun 29, 2011
    Posts:
    682
    I have same problem. I followed instructions and I am getting this message. Can someone help me please?
     
  21. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    Ok, for those who still have the problem with "create-jar" does not exist. It seems Ant was updated recently and some of the commands changed. I noticed that after doing "android update" with my setup, the "build.properties" file changed into "ant.properties" and there were some other changes. Ant was always saying that my build.xml file is absolete, so I made a backup copy of it in another folder, ran "android update" again and it created a new build.xml file with all the new syntax and rules they made. after that I just copied the settings from the old one into this one, so this is how my build.xml looks now:
    After this I see that I can at least try to compile the files.
    Now my problem is that it gives me an error about com.unity3d.player not existing, I added all the folders in the Environment Variables and I modified every file and I'm sure everything is set up accordingly, can there be any other issue why ant can't see my unity3d.player ?
     
  22. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Hi LastTemplar,
    Please Add
    ";C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin;" (without quotes) to "System Variable" in Path variable..
    It will solve ur problem.. I m Damn Sure..

    :D

    HAPPY TO HELP B-)
     
  23. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    PROBLEMS WITH ADMOB PACKAGE THEIR SOLUTIONS... (I will update this post, please tell me errors u get in Admob intergration..)

    Problem 1. Target compile does not exist in the project
    Solution: Problem is adb is unable to find ur ANT path in ur system. The solution of ur problem is, u have to add path to ur System Variables... Do these things restart ur system..

    1. Right Click on My Computer -> Properties.
    2. Goto Advanced -> click on "Environment Variables"
    3. In System Variables click on "New" Add VariableName="ANT_HOME" VariableValue="your path to Ant directory(not bin)". In my Case, VariableName=ANT_HOME VariableValue="C:\Android\android-sdk\tools\ant"(without quotes).
    4. Add another variableName="JAVA_HOME" its VariableValue="path to java directory"(not bin). In my case VariableValue="C:\Program Files\Java\jdk1.6.0_26"(without quotes).
    5. After adding these to variables click on "Path" variable in SystemVariable edit them. Add ";"(semicolon, without quotes).
    6. After Semicolon, add "%ANT_HOME%\bin" then again semicolon add "%JAVA_HOME%\bin", without quotes..

    7. Restart ur system seen if it will work..

    Reply if ur problem not yet solved.. ofcourse if u solved..



    Problem 2. Error about 'com.unity3d.player" not existing
    Solution:: Please Add
    ";C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin;" (without quotes) to "System Variable" in Path variable..

    It will solve ur problem.. I m Damn Sure..


    Problem 3: ./android update project etc... '.' is not recognized as an internal or external command, operable program or batch file.
    Solution:. "./"(Dot with forward slash) is MacOsX command to run executable file..
    In Windows, only "android update project etc.... " goto "tools" folder in android sdk execute this comment in comment prompt..

    Problem 4: Successfully compiled project Crashes on phone
    Solution:
    Add those line in AndroidManifest.xml..

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCAT ION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- to get Android Device ID -->


    Problem 4: "Building DEX Failed!" While building from ant..:
    Solution: Open the jar file named with ur bundle name (in my case its in.test.carm.jar) that u created with "ant create-jar" that is in "Plugin\Android\bin\" in ur Unity Project.

    Open with any compression software winrar\7Zip.

    and delete org folder from jar file and rebuild from Unity.. It worked.. :)

    That error is bcoz of same file "AdMobTestActivity.class" in ur project and also in "AdMob" package

    Just explore both folders in Jar file, u found the same file twice.. LOL...
     
    Last edited: Feb 15, 2012
  24. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    MicroEyes
    I quadruple checked everything, I have the paths, I have everything. I think the issue here is that I have a different version of Ant and Android SDK tools. Whenever I do an Android update it says the build.xml is obsolete so I let Ant create a new build.xml and it looks pretty much different from the one in the AdMobTest project.
    What versions of Ant and Android SDK tools do you use?
     
  25. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    To LastTemplar,

    I was using 1.7.* android sdk r12 at that when i was working on Admob.. but now i hav 1.8.2 Ant r15 for android... i didnt check on those version.. but i sure those will work with android..

    Can u send me ur build.xml come up with android package the modified one... may i could help u..

    Also r u still getting "Target compile does not exist in the project" ?
     
  26. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    MicroEyes
    Ok, this is the billionth time I started the tutorial all over, still no luck, could you please try to do this yourself using your current versions of the sdk and ant? From what I understand there is a lot of stuff that has to be changed.
     
  27. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Sure... i need a day to implement... :D.. reply here soon..
     
  28. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    That would be so cool. Thank you!
     
  29. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    You're a life saver :)
     
  30. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Hi LastTempler,
    i hav integrated Admob in a sample project with 1.8.2 Ant Android Sdk-r15, they r working fine, as it shud b...
    No prblem at all.. If want my project i can upload here... Shud i?

    Also, u would like to follow the same tutorial written on first second page or u want me to write another one?
     
  31. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    Could you please upload it here with instructions similar to how they were written on the second page?

    Thank you very much ;)
     
  32. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Let me Clear some steps:
    Setup ur Android SDK ANT for Unity
    1. Download Android SDK must be greater than 2.1.
    2. Download ANT and Setup.
    3. We'll configure it later..

    Configure Android SDK, ANT Unity on Windows...
    1. Right Click on My Computer -> Properties.
    2. Goto Advanced -> click on "Environment Variables"

    For ANT JAVA... (Please Choose your program paths)
    3. In System Variables click on "New" Add VariableName="ANT_HOME" VariableValue="your path to Ant directory(not bin)". In my Case, VariableName=ANT_HOME VariableValue="C:\Android\android-sdk\tools\ant"(without quotes).
    4. Add another variableName="JAVA_HOME" its VariableValue="path to java directory"(not bin). In my case VariableValue="C:\Program Files\Java\jdk1.6.0_26"(without quotes).
    5. After adding these to variables click on "Path" variable in SystemVariable edit them. Add ";"(semicolon, without quotes).
    6. After Semicolon, add "%ANT_HOME%\bin" then again semicolon add "%JAVA_HOME%\bin", without quotes..

    For Android (Please Choose your program paths)
    7. In Path Variable, add "C:\Program Files\Android\android-sdk\platform-tools" "C:\Program Files\Android\android-sdk\tools".

    8. For Unity (Please Choose your program paths)
    8. In Path Variable, add "C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer".(To avoid error "com.unityplayer.* not found").




    3. Download UnityPackage from Here:
    http://forum.unity3d.com/threads/77568-AdMob-plugin-that-works-in-Unity-3.2


    4. Replace all content in AdMobTestActivity.java to (Just Copy n Paste below code).. i tested on below code.

    package de.myproject.mygame;

    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.LinearLayout;
    import android.widget.RelativeLayout;
    import android.view.animation.*;

    import com.unity3d.player.*;

    import com.admob.android.ads.AdView;
    import com.admob.android.ads.SimpleAdListener;
    import com.admob.android.ads.AdManager;

    public class AdMobTestActivity extends UnityPlayerActivity
    {
    private AdView adView;

    protected void onCreate(Bundle savedInstanceState)
    {
    Log.i("AdMobTest", "onCreate");

    // super (UnityPlayerActivity) will use setContentView() ...
    super.onCreate(savedInstanceState);

    // ... so instead of using setContentView(), we call addContentView() from setupAds()
    setupAds();

    // Add test devices (check the logcat for the ID string of your device..)
    //AdManager.setTestDevices( new String[] { "80A354043041544216" } );
    AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR });
    }

    private void HideAd()
    {
    // Hide the ad.
    adView.setVisibility(View.GONE);

    // Fade the ad in over 4/10 of a second.
    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(400);
    animation.setFillAfter(true);
    animation.setInterpolator(new AccelerateInterpolator());
    adView.startAnimation(animation);//*/

    }

    //private void RotateAd()
    //{
    // // Hide the ad.
    // adView.setVisibility(View.VISIBLE);

    // // Fade the ad in over 4/10 of a second.
    // RotateAnimation animation = new RotateAnimation(0, 90, 24, 24);
    // animation.setDuration(400);
    // animation.setFillAfter(true);
    // animation.setInterpolator(new AccelerateInterpolator());
    // adView.startAnimation(animation);//*/

    //}

    private void ShowAd()
    {
    // Unhide the ad.
    adView.setVisibility(View.VISIBLE);

    // Fade the ad in over 4/10 of a second.
    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(400);
    animation.setFillAfter(true);
    animation.setInterpolator(new AccelerateInterpolator());
    adView.startAnimation(animation);//*/
    }


    private void setupAds()
    {
    // And this is the same, but done programmatically

    //LinearLayout layout = new LinearLayout(this);
    ////layout.setOrientation(LinearLayout.VERTICAL);
    ////layout.setGravity(Gravity.BOTTOM);
    //layout.setOrientation(LinearLayout.VERTICAL);
    //addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams .FILL_PARENT));

    LinearLayout main = new LinearLayout(this);
    main.setOrientation(LinearLayout.HORIZONTAL);
    main.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    //create horizontal section
    RelativeLayout.LayoutParams fpfp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONT ENT, LayoutParams.WRAP_CONTENT);
    LinearLayout horizontalLayout = new LinearLayout(this);
    horizontalLayout.setOrientation(LinearLayout.HORIZ ONTAL);
    horizontalLayout.setLayoutParams(fpfp);

    //RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONT ENT, LayoutParams.WRAP_CONTENT);
    //adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT );
    //adView = new AdView(this);
    ////layout.addView(adView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams .WRAP_CONTENT));
    //layout.addView(adView, adParams);

    adView = new AdView(this);
    horizontalLayout.addView(adView);

    adView.setVisibility(View.VISIBLE);
    adView.setBackgroundColor(0xff000000);
    adView.setPrimaryTextColor(0xffffffff);
    adView.setSecondaryTextColor(0xffcccccc);
    adView.setKeywords("Android game");
    adView.setRequestInterval(15);

    main.addView(horizontalLayout);
    //setContentView(main);
    addContentView(main, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


    // add listener for easier debugging
    adView.setAdListener( new SimpleAdListener()
    {
    public void onFailedToReceiveAd(com.admob.android.ads.AdView adView)
    {
    Log.d("AdListener", "onFailedToReceiveAd: " + adView.toString());
    super.onFailedToReceiveAd(adView);
    }

    public void onFailedToReceiveRefreshedAd(com.admob.android.ads .AdView adView)
    {
    Log.d("AdListener", "onFailedToReceiveRefreshedAd: " + adView.toString());
    super.onFailedToReceiveRefreshedAd(adView);
    }

    public void onReceiveAd(com.admob.android.ads.AdView adView)
    {
    Log.d("AdListener", "onReceiveAd: " + adView.toString());
    super.onReceiveAd(adView);
    }

    public void onReceiveRefreshedAd(com.admob.android.ads.AdView adView)
    {
    Log.d("AdListener", "onReceiveRefreshedAd: " + adView.toString());
    super.onReceiveRefreshedAd(adView);
    }
    } );

    adView.requestFreshAd();
    }
    }

    5. Follow these instructions:-

    Download the unity admob package and import it to your project. For the following steps let's say the project folder is "\syslord2k2\Unity\myproject" (%myproject%) while the android sdk folder is "\syslord2k2\android-sdk" (%androidsdk%).

    In your project click on File > Build Settings, choose Android, click Player Settings and find your bundle identifier, for example "de.myproject.mygame".

    Find AdMobTestActivity.java in your project folder under "Assets\Plugins\Android\src\org\example\AdMobT est" and open it with a text editor.

    Update the package name in Line 1 with your bundle identifier, for example change "package org.example.AdmobTest" to "package de.myproject.mygame".

    Uncomment lines 72 and 73 and change the values to your keywords and your desired interval.

    Save the file and rename the folder structure according to your bundle identifier, for example change "org" to "de", "example" to "myproject" and "AdMobTest" to "mygame" (Don't know if this step is necessary but it looks better ).

    Open AndroidManifest.xml in "%myproject%/Assets/Plugins/Android".

    In line 3 change "package = "org.example.AdMobTest" according to your bundle identifier, for example to "package = 'de.myproject.mygame";

    In line 19 change the string "YOUR_ID_HERE" to your publisher id, obtained through the admob online platform.


    Add these Permissions to XML Files.:---
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCAT ION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    Save and exit AndroidManifest.xml.

    Open up a terminal and type "cd %androidsdk%\tools" so in my case "cd \syslord2k2\android-sdk\tools" to change to the android-sdk\tools folder.

    Type "./android update project -t 2 -p %myproject%\Assets\Plugins\Android" so in my case "./android update project -t 2 -p \syslord2k2\Unity\myproject\Assets\Plugins\Android "
    (Note: the -t paramete defines the target you are building for, you can see a list of available targets by typing "./android list targets")

    Change to your project folder by typing "cd %myproject%\Assets\Plugins\Android" so in my case "cd \syslord2k2\Unity\myprojec\Assets\Plugins\Android" and type "ant create-jar".

    In the finder delete the "%myproject%\Assets\Plugins\Android\bin\org.ex ampl e.AdMobTest.jar" and the "org" folder in the "%myproject%\Assets\Plugins\Android\bin" folder. (Of course only do this if your bundle identifier does not start with "org" . This step is pure cosmetics and to reduce filesize, it does not add or substract functionality.)



    Any Problem... Plz share with me..
     
    Last edited: Feb 17, 2012
  33. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    Ok, what I get right now is the same error I had before "You are using an obsolete build.xml", also, when I do android update, it says this:

     
    Last edited: Feb 17, 2012
  34. lyh1

    lyh1

    Joined:
    Jun 30, 2010
    Posts:
    92
    Any chance to get it work with UnityNativePlayerActivity?
     
  35. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    LastTemplar,
    Have u changed min Android SDK version in AndroidManifest.xml...
    Please do that with u r using..

    :D
     
  36. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    I changed it to <uses-sdk android:minSdkVersion="15" /> and when I run android update, it gives me the same thing.
     
  37. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    I dont know if its releveant or not but I'm using WinAnt.
     
  38. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    I can't do it...FML
    MicroEyes your tutorial it's nice but there are parts where I'm not getting it.
    Are you sure the path of ant is there? I think we have to use the apache one..
    Anyway.. When I try to update the project with that build.xml it fails saying it's to old.. So I delete the file.. And it generates a new one...
    But the Ant create-jar... doesn't work.. Has it change?
    So I try Ant debug and it starts compiling but then it gives errors in the java... =\

    Edit: it's with package com.unity3d.player does not exist but I've put the path on the system variable..=(
     
    Last edited: Feb 18, 2012
  39. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    So... no one knows what do anymore?
     
  40. Joel-Santos

    Joel-Santos

    Joined:
    Feb 23, 2010
    Posts:
    118
    Ok I am trying a much easier way. Right now it works but the ads are no showing. If I can fix it I'll post a tutorial explaining how I did it. Right now I have to work... But later I'll give it a try. All I can say is forget ant and use eclipse.
     
  41. LastTemplar

    LastTemplar

    Joined:
    Nov 7, 2011
    Posts:
    12
    Tried it already with eclipse, I can't really understand how everything is handled regarding the integration with eclipse and I'm getting pissed because I can't make a simple code run for a week now.
    I will be really grateful if you could post your tutorial here 'cause I'm getting desperate over here.
    Thank a lot!
     
  42. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Sorry Guys, i was on off from last 3 days.. I have completed my video tutorial on Admob. 2morow promise, i'll post a video on Admob integration on fresh system..
    Keep in Touch..

    THANKX :)
     
  43. doudoudoudou

    doudoudoudou

    Joined:
    Feb 23, 2012
    Posts:
    2
    It crashes on my phone when it startup. The splash of unity do not show.
    I build the apk with unity3d 3.5 and my phone is Nexus S.
    I do nothing but just import the package and build the project.

    please help! Thanks!
     
  44. doudoudoudou

    doudoudoudou

    Joined:
    Feb 23, 2012
    Posts:
    2
    My mistake, I do not change the package name of unity project.
     
  45. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Apologize Again Friends, i couldn't help u bcoz of limited tym i hav.. I m suggesting you all to work with Android r12 sdk ANT 1.7.*.
    They will work fine. i had worked with that configuration..

    Gud Luck.
     
  46. Somedays

    Somedays

    Joined:
    Jan 2, 2012
    Posts:
    214
    Hey I've been studying this entire thread for a few days now, and followed the tutorials.

    When I do ant create-lib i get an error:

    C:\Program Files (x86) Android\android-sdk\tools\ant\build.xml:600: Compile failed; see the compiler error output for details.

    Any suggestions?

    EDIT: Here's a pic
     
    Last edited: Feb 26, 2012
  47. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
  48. Somedays

    Somedays

    Joined:
    Jan 2, 2012
    Posts:
    214
    I just want to say thanks for your time and helping everyone, MicroEyes.

    As for your post I believe I'm following everything... I set the paths just like you said and did everything else. I don't know what is wrong!
     
  49. MicroEyes_old

    MicroEyes_old

    Joined:
    Jun 9, 2011
    Posts:
    188
    Hi SomeDays,
    As i m seeing in your post pic, that error is occurred when user unity directory path to System Variable is not set... please set that thing..

    Please Add
    ";C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin;" (without quotes) to "System Variable" in Path variable..


    ";C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin;" is my unity path.. please check urs... reply..
     
  50. Somedays

    Somedays

    Joined:
    Jan 2, 2012
    Posts:
    214
    I changed some things around, now I'm getting the message ANT_HOME wasn't setup correctly.
    Here's exactly what I have:

    User Variables I added:
    ANT_HOME C:\Program Files (x86)\Android\android-sdk\tools\ant
    JAVA_HOME C:\Program Files\Java\jdk1.6.0_30

    System Variables:
    Inside of PATH

    C:\Program Files\Java\jdk1.6.0_30\bin\java.exe;
    C:\Program Files\apache-ant-1.8.2\bin;
    C:\Program Files (x86)\Android\android-sdk\tools;
    C:\Program Files (x86)\Unity\Editor\Data\PlaybackEnginesandroidplayer\bin;
    C:\Program Files (x86)\Android\android-sdk\platform-tools;
    C:\Program Files\Java\jdk1.6.0_30\bin;
    C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\bin;
    %ANT_HOME%\bin;
    %JAVA_HOME%\bin;

    Please let me know if anything doesn't belong or if I'm missing anything =/

    Perhaps it has something to do with the 32 or 64 bit versions of everything? Does the jdk, unity, and android sdk all have to be the same bit versions?
     
    Last edited: Feb 26, 2012
unityunity