Google Admob with Unity3D

Monetization is desired by game developers and standard app developers alike.  For the developers that would like to keep their work free to download, in app advertising is often a good choice.  Admob by Google is convenient for ads because it is compatible with iOS and Android without changes to the Unity3D project.

Start by downloading the latest Admob Plugin and importing it into your Unity3D project.  To do this, from the Assets menu item, choose Import Package and then choose Custom Package.

Import Custom Package
Import Custom Package

Choose to import the GoogleMobileAds.unitypackage file that was downloaded from Google’s Github repository and make sure to leave everything checked.

Create a new empty GameObject in your project.  This object will be used to initialize your Admob ads so go ahead and name it Admob.  In the Github repository there is a nice sample script to be used as a component on the object.  Below is a slightly modified version of the sample script:

This version of the script will only show the ad if on an Android or iOS device.  This means you don’t have to touch your project or code set if you plan to compile for Windows Phone or anything else.

Now this is where it gets a little complicated.  You must add the Google Play Services library into the /Assets/Plugins/Android directory of your Unity3D project.  The Google Play Services library can be found in /Android-SDK/extras/google/google_play_services/libproject.  Copy the entire directory that resides in libproject.  Building and running for Android should work without issues at this point.

For iOS you must do extra steps.  Download the latest Admob iOS SDK and import the following files into the classes group of your Xcode project:

  • GADAdMobExtras.h
  • GADAdNetworkExtras.h
  • GADAdSize.h
  • GADBannerView.h
  • GADBannerViewDelegate.h
  • GADInterstitial.h
  • GADInterstitialDelegate.h
  • GADRequest.h
  • GADRequestError.h

Import the following files into the library group of your Xcode project:

  • libGoogleAdMobAds.a

The iOS project is not quite complete yet.  You must add -ObjC to the Other Linker Flags of your application and add the following frameworks if they have not already been added:

  • AdSupport
  • AudioToolbox
  • AVFoundation
  • CoreGraphics
  • CoreTelephony
  • MessageUI
  • StoreKit
  • SystemConfiguration

Building the Xcode project at this point should be successful.

Resources
Google Admob Plugin for Unity3D
Google Admob SDK for iOS and Android

Nic Raboy

Nic is a skilled application developer who has released several native and hybrid mobile applications to iTunes and Google Play. He writes about his development experiences related to making web and mobile app development easier to understand and has experience in Android, Node.js, Apache Cordova, Java, NoSQL, SQL, GoLang, NativeScript, and Unity3D.

  • I just wish to say that your instruction has helped me integrated admob into two of my games. Thank you very much.

    • I’m glad you found these instructions useful 🙂

  • Psydack

    Thanks guy!

  • Øystein

    I can’t find the google play services library… Please help!

    • Did you install it when you set up Android? It doesn’t ship with the Android SDK by default. You must open up the Android manager and choose to install it.

      Regards,

      • Øystein

        I’m building for iOS on my mac, do i still need it?

  • Øystein

    Okey, Thank you for fast answer!