add adMob banner to your unity3d game using unity2eclipse

a great benefit about using unity2eclipse is the possibility to extend your unity3d projects with native android elements like buttons or layouts. as a practical example we decided to show you the integration of an adMob banner in your game.

first of all you have to create an eclipse project – the easiest way to do that is to use our unity2eclipse plugin of course! 😉 click here to learn how to do that.

once created we add the adMob SDK to the project:
right click on the project name, find Properties in the menu (it is located at the very bottom). selecting the properties will open a settings window – navigate to Java Build Path -> Libraries -> Add External JARs… select the previously downloaded adMob .jar file and click OK.

Java Build Path -> Libraries -> Add External JARs…

the ugly thing about the latest android SDK update is the requirement to copy the adMob .jar  file manually into the libs folder of your project too. i am not sure if this is a bug or a feature, but adding it twice is the only solution that worked for me. just drag & drop it from your finder/windows explorer into eclipse.

additional location of the adMob .jar file

lets start with the more fun part of the tutorial and create a layout file that contains a placeholder for our unity player and the adMob banner – we’ll name it unitylayout.xml and store in res/layout folder of our project.

create a new layout xml file here

the contents of the XML layout:

<?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android=""
    android:layout_height="match_parent" >

        android:orientation="vertical" />

        ads:loadAdOnCreate="true" />


(replace the “useYourIdHere” with your adMob ID 😉 )
we’ll use a FrameLayout – it will allow us to position widgets on top of each other – in our case the banner view on top of the unity player (learn more about android layouts)

in the next step we’ll adjust the .java class file:
the established way to implement an unity player here is to extend the UnityPlayerActivity:

public class myUnityProject extends UnityPlayerActivity

its fine, but it wont allow you to add any native android widgets to your app. we’ll change it, extend an Activity and push the unity player into the LinearLayout placed in our layout xml file. you can replace the whole content of the class with this code:

public class myUnityProject extends Activity
	protected void onCreate(Bundle savedInstanceState) 
		LinearLayout playerHolder = (LinearLayout) findViewById(;
		UnityPlayer myPlayer = new UnityPlayer(this);
        myPlayer.init(1, false);

the last file that we need to edit is the Manifest.xml located in the root of our project. adMob SDK requires some permissions in order to be displayed correctly:

<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="15" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="true" />


i hope that this little tutorial will help you to understand how to extend the functionality of your unity android game and to benefit from adMob integration.

2 thoughts on “add adMob banner to your unity3d game using unity2eclipse

  1. Thank you for the wonderfull tutorial..
    But i am getting an error in “packgaeName”

    “LinearLayout cannot be resolved to a type” what to do about it??

Leave a Reply

Your email address will not be published. Required fields are marked *