Unity SDK Integration

893ad6d-Unity_icon.png

Current SDK Version: 3.27.0

 

Introduction

This guide is intended for developers who are integrating the FairBid SDK with a Unity app.

Prerequisites

  • Android 4.1 (API level 16)+ (when building for Android)
  • iOS 9.0+ (when building for iOS)
  • Unity 2019 LTS or later

Important

  • The FairBid Unity SDK can only build iOS projects from a Mac - you cannot build your Xcode project on Windows.
  • All Fyber SDKs and supported mediated networks work in conjunction with Android's 64-bit architecture.

Integration Methods

Fyber supports two methods for the integration of Unity:

  1. Integration through Unity's Package Manager
  2. Importing FairBid Unity Plugin Raw Package

Integrating Through Unity's Package Manager

Note

This is the recommended method to integrate the FairBid SDK in your Unity project.

The FairBid Unity Plugin is provided as a package in the NPM package registry. This package is imported using Unity Package Manager.

To import the package:

  1. Add the following entries inside your manifest.json file, which you can find under the Packages folder:
  • Add an entry under scopedRegistries, so that unity knows where to search when adding the FairBid Unity Plugin dependency. This entry points to the NPM package registry:
{
    …
    "scopedRegistries": [
        {
            "name": "npmjs",
            "url": "https://registry.npmjs.org/",
            "scopes": [
                "com.fyber.fairbid.unity"
            ]
        }
        …
      ],
    …
  }
  
  • Add an entry under dependencies, which references the FairBid Unity Plugin version that you intend to integrate:
{
    …
    "dependencies": {
        "com.fyber.fairbid.unity": "3.27.0",
        …
    }
    …
  }
  
  1. Save the changes and open your Unity 3D Project.

The Unity Package Manager resolves the dependencies and now the Fyber FairBid Unity package should be integrated in the project.

Additionally, to cross-check the integration of Fyber FairBid:

  1. Go to the “Window” toolbar menu of Unity 3D
  2. Click Package Manager

You should see the following window pop-up with FairBid under the section Fyber and the FairBid SDK version:

You also have the possibility to change the version of the FairBid Unity Plugin that you are integrating through the Unity Package Manager.

Important

The integrated FairBid Unity Plugin is a lightweight dependency. You must add the sources of the native FairBid SDKs for the platform you are building. Follow the instructions for the platform specific set-ups below.

Importing FairBid Unity Plugin Raw Package

Follow the instructions below to manually download the FairBid Unity Package.

Manual Download

 

Removing Current Plugin

If you are updating the Plugin:

  1. Make sure there is no trace of the previous version of the FairBid Plugin
  2. Remove the FairBid folder

This is a fail-safe way to ensure no legacy file is left behind:

   

If your current FairBid Plugin pre-dates version 3.4.1 refer to Migrating from the Old to New Structure below to ensure it is correctly removed.

Importing New Plugin

  1. Download the FairBid SDK
  2. Unzip the downloaded files
  3. Add the FairBid.unitypackage to your open Unity project

Important

The integrated FairBid Unity Plugin is a lightweight dependency. You must add the sources of the native FairBid SDKs for the platform you are building. Follow the instructions for the platform specific setups below.

OS Specific Setup

Android Specific Setup

 

Modifying Your Manifest.xml

If your application targets API 31 or greater (Android 12) you must declare the AD ID permission:

 <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Failing to do so will prevent FairBid SDK (and all mediated networks) from accessing the Android's Advertising ID which will result in reduced ad inventory and thus, lower revenues.

More information about this permission can be found on Android's official documentation

Integrating the SDK plugin

The FairBid SDK plugin must be added to your project.

You have to include some additions to your gradle scripts. First ensure that you have enabled the following options in your Player Settings:

Unity_2019_LTS_android_settings.png

This will create the following files:

baseProjectTemplate.gradle

- launcherTemplate.gradle

- mainTemplate.gradle

Starting from SDK version 3.27.0, the steps below are no longer required. The FairBid SDK plugin is added automatically to your project.

If you are using FairBid SDK Plugin below 3.27.0, you must include it in your project.

To do this:

  1. Open your baseProjectTemplate.gradle file and add the following:
buildScript {
repositories {
...
mavenCentral()
...
}
dependencies {
...
classpath 'com.fyber:fairbid-sdk-plugin:3.27.0'
...
}
}
allProjects {
repositories {
...
mavenCentral()
...
}
}
  1. Open your launcherTemplate.gradle file and apply the plugin by adding the following:
plugins {
...
id 'com.fyber.fairbid-sdk-plugin' version '3.27.0'
...
}

Note that this script is the one including the apply plugin: 'com.android.application' . This is also the template in which you will include your mediation dependencies.

iOS Specific Setup

The FairBid iOS SDK dependency must be added to your project.

You must Build and run your Unity 3D project and then add the Fyber FairBid iOS SDK pod in your Podfile.

Recent versions of Unity 3D (since 2019.3) create a target named UnityFramework. If this is your case and you can see this target inside your Podfile, then add the FairBid iOS SDK dependency under it. Otherwise, add it to the standard target. Then run the pod install command, in exactly the same way you would for a native integration:

  target 'UnityFramework' do
  
    # Pods for UnityFramework
    pod 'FairBidSDK', '~> 3.27.0'
    
  end
  

Back to Top ⇧