Getting Started

The Audience Network Unity SDK delivers ads for publishers using Unity within their iOS and Android apps. The Unity adaptor can be used for banner, interstitial, rewarded video and native ads.

Ensure you have completed the Audience Network Getting Started guide before you proceed.

Prerequisites

Requires Unity 5.0 or later.

Ensure that you have the latest tools installed:

  1. Unity
  2. Xcode
  3. Android Studio

Adding Audience Network Ad to Unity App

Step 1: Download Audience Network Unity SDK

Step 2: Create and Setup Audience Network Unity Sample Project

Step 3: Build iOS app from Unity Project

Step 4: Build Android app from Unity Project

Step 1: Download Audience Network SDK

The Audience Network Unity SDK is part of the Facebook SDK for Unity. To get started, download and extract the Facebook SDK for Unity.

Step 2: Create and Setup Audience Network Unity Sample Project

After you have installed Unity and downloaded the latest Audience Network Unity SDK, you can open the Unity app and create a sample project.

  1. Open the Unity app and name the project AudienceNetworkUnityTutorial, and set the location where you want to store your project.
  2. In the Unity editor, select from the menu Assets, Import Package and then Custom Package…, then select the audience-network-unity-sdk.unitypackagee from the AudienceNetworkSDK folder to import the plugin into your project.


    After Audience Network SDK is imported, you will be able to navigate the SDK content from Project panel as follows:



  3. In the Unity editor project panel, you should see AudienceNetwork folder created under Assets folder. Open Samples folder, you will see AdViewScene, InterstitialAdScene, RewardedVideolAdScene and NativeAdScene which are Unity scene files. AdViewTest.cs, InterstitialAdTest.cs, RewardedVideoAdTest.cs and NativeAdTest.cs are cs files used for calling Audience Network API to request and load ad content.

    Double click to open AdViewTest.cs and search for YOUR_PLACEMENT_ID. You will see the following call.
    AdView adView = new AdView ("YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);</code>
    Replace YOUR_PLACEMENT_ID with your own placement id string. If you don't have a placement id or don't know how to get one, refer to the Getting Started Guide. Repeat this for InterstitialAdTest.cs, RewardedVideoAdTest.cs and NativeAdTest.cs.

  4. Double click NativeAdScene and click Play button at top panel, you will be able to see Audience Network Test ad by default as follows:

Step 3: Build iOS app from Unity Project

After you have created a sample Unity Project that is integrated with Audience Network Unity SDK, you will learn how to create iOS app that can show Facebook Audience Network ads.

Please see the FAQ for minimum OS version supported by Audience Network SDK.

  1. Double click AdViewScene from Samples folder and choose File -> Build Settings. From Scenes In Build window, click Add Open Scenes button and select AudienceNetwork/Samples/AdViewScene. Repeat this step for InterstitialAdScene, RewardedVideoAdScene and NativeAdScene as follows:

    Select iOS platform and click Build And Run. It will take a few seconds to create a sample iOS project.

  2. Open the Xcode project after it is built from Unity. Click Project file and select the target build from Targets menu. Check if you have the valid bundle identifier as follows:



    Note that XCode will create a bundle identifier for your project. In this example, the bundle identifier is com.yourcompany.AudienceNetworkTutorial. You will use this bundle identifier later when you submit your app for approval as explained in Submit For Review.

  3. Unity Native Plugin does not provide API to add dependent libraries to be linked for the iOS project. You will see the following build errors:
    Undefined symbols for architecture arm64:
      "_xmlXPathFreeObject", referenced from: lxml::xpath::object::object(_xmlXPathObject*) in FBAudienceNetwork(FNFMediaPresentationDescription.o)
    To fix the above build error, you would need to add '-lxml2' to 'Other Linker Flags' in Build Settings page in your project as follows:



  4. Add StoreKit.framework to Linked Frameworks and Libraries as follows:



  5. Choose your build target to be device, build and run the project. You can see Audience Network ads from an app that is built from Unity as follows:

Step 4: Build Android app from Unity Project

The minimum OS version of Android supported by Audience Network SDK is API Version 11 of the Android SDK.

  1. Double click AdViewScene from Samples folder and choose File -> Build Settings. From Scenes In Build window, click Add Open Scenes button and select AudienceNetwork/Samples/AdViewScene. Repeat this step for InterstitialAdScene, RewardedVideoAdScene and NativeAdScene as follows:

    Select Android platform, Google Android Project, and Development Build options.

  2. Click Player Settings. In Other Settings -> Identification -> Version, select "Android 4.1 'Jelly Bean' (API level 11)".


  3. Choose Gradle(New) for Build System. Click Build And Run. It will take a few seconds to create a sample Android project.

    Internal Unity build are not supported anymore. Builds should be done with Gradle. (Build Settings, select Build System)


  4. Open Android Studio and select Import project.



    Locate the android project built by Unity to build the gradle project.



  5. After the gradle project is created by Android Studio, open AndroidManifest.xml and add following elements if missing:
    <activity android:name="com.facebook.ads.AudienceNetworkActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  6. Select Deployment Target to be your Android device. You can see Audience Network ads from an app that is built from Unity as follows:

Next Steps