Getting Started

Facebook Audience Network allows you to monetize your Android apps with Facebook ads. This guide will walk you through all the steps to get the SDK integrated.

Prerequisites

Ensure that you have Android Studio installed.

Getting Started Steps

Step 1: Creating a New Project

Step 2: Including the SDK

Step 3: Configuring your Manifest

Step 1: Creating a New Project

You can skip this step if you already have a project you want to integrate Audience Network into.

Start Android Studio and select "Start a new Android Studio Project"



Name your project and specify your company's domain.
The Package name will be your identifier if you decide to upload your app to the Google Play store.



Set your minimum Android SDK version. Audience Network requires API 15 or higher, but for the sake of
these samples, we will use API 21.



Add an Empty Activity to your Project



Name your initial Activity and click Finish.

Step 2: Including the SDK

The Audience Network SDK is part of the Facebook SDK. Follow these steps to download and include it in your project:

Using Gradle



Add the following compile statement to your app-level build.gradle (not project!), to use the latest Audience Network SDK:

dependencies {
  ...
  compile 'com.facebook.android:audience-network-sdk:4.+'
}

If there are issues resolving the Audience Network SDK, make sure that you've synced your Gradle file and try restarting Android Studio.

Manual installation (Not Recommended)

If using Intellij IDEA or Eclipse, download and extract the Facebook SDK for Android. Under the AudienceNetwork/bin folder, copy the AudienceNetwork.aar file and place it in the /libs folder in your project (you might need to create the directory if it doesn't already exist). Then add the following lines to your app's build.gradle:

repositories {
  flatDir {
    dirs 'libs'
  }
}

dependencies {
  ...
  compile(name: 'AudienceNetwork', ext: 'aar')
}

If using AudienceNetwork.jar for your project, under the AudienceNetwork/bin folder, rename the AudienceNetwork.aar to AudienceNetwork.zip, extract classes.jar file and rename it to AudienceNetwork.jar, place the AudienceNetwork.jar file in the /libs folder in your project (you might need to create the directory if it doesn't already exist). Make sure your IDE's UI reflects this change. If you are using Intellij IDEA or Eclipse, right click on the libs/AudienceNetwork.jar file and choose 'Add as Library'.


If you are not already including it, add the Android v4 Support Library (without resources) and v7 Recyclerview Library to your project, detailed steps can be found here.

Though not required, we recommend that you set up your project to work with Google Play Services as indicated here. This will enable the Audience Network SDK to fetch the Advertising ID more efficiently.

Step 3: Configuring your Manifest



You'll need to configure your app's manifest file as follows:

  • Add the INTERNET and ACCESS_NETWORK_STATE permissions:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.audiencenetworktutorial">
  ...
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  ...  
</manifest>
  • Include AudienceNetworkActivity under the application element:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.audiencenetworktutorial">
  ...
      <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
    ...
    <activity android:name="com.facebook.ads.AudienceNetworkActivity"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    ...
  </application>
  ...
</manifest>

Next Steps