Android SDK Integration

0e05303-Android_icon.png

Current SDK Version: 3.9.0

 

Introduction

This guide is intended for developers who are integrating the FairBid SDK with an Android app. After you have integrated the SDK, you must choose the relevant ad format and follow the steps for implementing that format.

Prerequisites

  • Android 4.1 (API Level 16)+
  • Google Play Services 11.4.0+

Important

All Fyber SDKs and supported mediated networks work in conjunction with Android's 64-bit architecture.

Step 1: Integration

Fyber supports both Gradle dependencies or manual download to integrate our SDK:

Gradle

Add Fyber's maven repository and dependencies to your gradle build script:

  1. Add the following to your app’s project level build.gradle file inside the repositories section:

In project level build.gradle there are usually two repositories sections - one for buildscript and one for allprojects. Add the entry in allprojects.

Maven Repositories (Excerpt)

allprojects {
repositories {
maven {
url "https://fyber.bintray.com/maven"
}
}
...
}
  1. Add the following to your app’s app level build.gradle file inside the dependencies section:

Dependencies (Excerpt)

dependencies {
...
implementation 'com.fyber:fairbid-sdk:3.9.0'
...
}
  1. Starting from FairBid SDK 3.0.0, if you support Android SDK below 26, you must add the following snippet to the Android section:

Java Version Compatibility

android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}

Historically, Android projects have been using Java 1.7 since it was the surest way to ensure compatibility across Android versions.

Android Studio has been supporting partial compatibility with Java 1.8 since version 3.0.0. As some of our partners begin moving to 1.8, we follow suit.

It simply allows our team (and our partners) to leverage some new features of the Java language with no implications on runtime/API compatibility.

However, it enforces the same type of declaration in the projects integrating FairBid SDK.

Manual Download 

  1. Download the FairBid SDK
  2. Extract inner zip file
  3. Import the aar packages into your project.

Step 2: Adding Google Play Services

The Google Play Services SDK must be added to your project. Follow Google's documentation on integrating the Google Play Services SDK into your app.

Only the Ads and Location APIs are included. If you are using a Gradle build system with Android Studio adding the following to build.gradle is sufficient:

  1. Add the following to your app’s build.gradle:

Importing Google Play Services

implementation 'com.google.android.gms:play-services-ads-identifier:17.+'
// Optionally, add the location services
implementation 'com.google.android.gms:play-services-location:17.+'
  1. Modify your Android Manifest
  2. Add the following to your app’s manifest.xml within the tag:

Add Google Play Services to your AndroidManifest.xml

<!-- Google Play Services -->
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>

Google Play Services Meta-Data

This tag is not allowed outside the application tag but will not raise any critical warning if you put it outside.

Step 3: Modifying Your Manifest.xml

  1. Add the following attribute to the tag to enable hardware acceleration:

Hardware Acceleration

<application android:hardwareAccelerated="true" ...>

Optional Permissions

The following permissions are not required for our SDK or 3rd-party SDKs to function, but including them in your AndroidManifest.xml may result in improved eCPM and user experience:

Optional Permissions

<!-- Optionally used by FairBid -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Step 4: Adding 3rd Party SDKs

In addition to integrating the FairBid SDK, publishers who are using FairBid Mediation, must integrate chosen 3rd-party networks' SDKs into their app.

  1. Set up your app in the network's dashboard and in the Fyber dashboard. A step-by-step guide can be found here.
  2. Download the relevant network's SDK. Supported networks and their SDKs can be found here.
  3. Add additional manifest modifications

Note

You must add additional manifest modifications for each third party network. These entries are found by selecting your third party adapters here.

Important

The FairBid SDK automatically detects and initializes SDKs from 3rd-party networks.

Building for AndroidX

If you, or any of your integrated mediation networks use AndroidX libraries, you can update your build to ensure compatibility. To use androidx-namespaced libraries in a new project, you must set the compile SDK to Android 9.0 (API level 28) or higher.

If you have a native integration, add the following parameters to your gradle.properties file:

Groovy

android.useAndroidX=true
android.enableJetifier=true

If you have a Unity integration, the way to add gradle properties to the build differs from the native build. This is because your mainTemplate.gradle does not really belong to a gradle project in the place it is located.

Therefore, you should provide the previous properties by adding the following to your mainTemplate.gradle.

Groovy

project.ext.set('android.useAndroidX', true)
project.ext.set('android.enableJetifier', true)

It is important to write this before you apply the following plugin:

Groovy

apply plugin: 'com.android.application'

More information about AndroidX here.