Integrate Flurry SDK for Android

Integrating with the Flurry SDK is easy and straightforward for Android developers.

Follow these instructions and in no time at all, you’ll be ready to start logging events and publishing your ads.

Prerequisites: Android API level 10 and higher.

Create an App & Get Your API Keys

Start by creating an app. Once you create the app, you’ll receive a Flurry API Key, which you’ll need when using the SDK.

Sign up  or  Create an App for Android

Note

For each distinct app that you create, you’ll need to acquire a unique Flurry API Key.

Install Flurry Android SDK

We recommend installing the Flurry SDK via jcenter. Instructions for this, as well as manually downloading and adding the .jar files.

Option 2: Install .jar files from the Flurry Dev Portal

Follow these steps:

  1. Download .jar files from Flurry Dev Portal

The downloaded archive should contain these files for use with Flurry Analytics:

  • flurryAnalytics.jar: The library containing Flurry’s analytic collection and reporting code.
  • flurryAds.jar: The optional library to incorporate Flurry’s ads into your application.
  • ProjectApiKey.txt: This file contains the name of your project and your project’s API key.
  • FlurryAndroidAnalyticsReadmevx.y.z.pdf: A PDF file with instructions (where x.y.x denotes the latest version of Flurry SDK).
  1. Add .jar files to your project. This can be performed using Android Studio or Eclipse.

Using Android Studio:

  1. Add flurryAnalytics.jar to your project’s libs folder.
  2. If you also want to integrate Flurry Advertising, add the flurryAds.jar to your project’s libs folder.
  3. Navigate to File > Project Structure > Module > Dependencies. Click the ‘+’ button in the bottom of the ‘Project Structure’ popup to add dependencies. Select ‘File dependency’ and add libs/flurryAnalytics.jar.
  4. Add Google Play Services library. If selectively compiling individual Google Play Service APIs, you should include the Google Analytics API.

Using Eclipse

  1. Add flurryAnalytics.jar to your project’s libs folder. Right-click on each JAR file and select Build Path > Add to Build Path.
  2. If you also want to integrate Flurry Advertising, add the flurryAds.jar to your project’s libs folder.
  3. Right-click on each JAR file and select Build Path > Add to Build Path.
  4. Add the Google Play Service library jar file.

Configure the AndroidManifest and ProGuard Files

Below is an example of an AndroidManifest.xml file configured for both Flurry Analytics and Flurry Advertising.

Configure Your Proguard.cfg File (Optional)

The following step is only necessary if you are using Proguard to obfuscate your code.

Add the following instructions to your proguard.cfg file:

# Required to preserve the Flurry SDK
-keep class com.flurry.** { *; }
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod,Signature
-keepclasseswithmembers class * {
    public (android.content.Context, android.util.AttributeSet, int);
}

Initialize Flurry

Add the following calls to initialize the Flurry SDK by using the FlurryAgent.Builder to initialize the Flurry SDK with your project’s API key:

public class MyApplication extends Application {
  @Override
  public void onCreate() {
      super.onCreate();

      new FlurryAgent.Builder()
          .withLogEnabled(true)
          .withListener(flurryListener)
          .build(this, FLURRY_API_KEY);
  }
}

Note

If you want to call logEvent() directly after calling build(), it is best to register a Flurry Agent listener with withListener() to make sure the SDK is initialized before logging. If you wish to make calls to logEvent() directly after initializing the SDK, it is best to register the listener FlurryAgentListener.onStartSession() for when the session has started. This will allow you to capture events as soon as the session is ready.

If your app is targeting Gingerbread or Honeycomb(API 10 -13), follow these steps:

  1. Insert a call to FlurryAgent.onstartSession(Context) in your Activity’s onStart() method. Do not pass in the global Application context.
  2. Insert a call to FlurryAgent.onEndSession(Context) in your Activity’s onStop() method. Do not pass in the global Application context.

Now test run your Android app and ensure that it builds without errors. If everything is working properly, a session will be recorded in Flurry and should be visible on your Real Time dashboard within 30 seconds.

Important

If you created the Flurry app within the last 5 minutes, the app may not yet be live on our servers and thus will not reflect real-time data. Re-run your app after 5 minutes to see your session recorded on the Real Time dashboard.

Congratulations! Your Android app is now ready to be used with Flurry Analytics, and if you’ve integrated the Flurry Ads library, Flurry Advertising

Need Help?

Check out our robust collection of FAQs and a detailed Lexicon of key terminology. Didn’t find what you were looking for. Our team is answering questions on Flurry Forums.

Have Feedback?

We’d love to hear your suggestions for us. Please visit our Feedback Board to submit your ideas.