Mobile Integration Guide - Android

moesif-android is a SDK that automatically captures HTTP traffic such as to your internal APIs or external APIs like Stripe.


This lib requires the use of OkHttp 2.2 or better. OkHttp 3.x is also supported.

The two popular Android networking clients (Volley and Retrofit) support using OkHttp so you are probably fine if using one of these two libs.

If using Retrofit, 1.9 or greater is required. If using Volley, a simple one line change is required to use our MoesifOkHttpXStack.

Module Structure

moesif-android: The core SDK shared across platforms, imported automatically by the below HTTP stack specific modules.

moesif-android-okhttp3: Supports the latest version (3.x) of OkHttp

moesif-android-okhttp2: If you want to stick with OkHttp 2.x for legacy reasons, import this module instead of moesif-android-okhttp3

How To Configure:

1. Add the dependency to your app/build.gradle

repositories {
    maven { url "" }

dependencies {
    compile 'com.moesif.moesif-android:moesif-android-okhttp3:1.0.0'

If your Android project imports Volley as an unmanaged artifact, you may have to exclude volley as a transitive dependency: Otherwise, you may get duplicate class errors. gradle compile ('com.moesif.moesif-android:moesif-android-okhttp3:1.0.0') { exclude group: '' }

2. In your AndroidManifest.xml, add your Moesif ApplicationId under the “application” node:


    <!-- Your other code -->

        android:value="your_moesif_application_id" />

3. In your Application’s onCreate(), initialize the lib


public final class MyApplicationClass extends Application {

    public void onCreate() {

4. Add the Interceptor

4.a If using Retrofit/OkHttp3 natively:

Add the Moesif MoesifOkHttp3Interceptor when building the Retrofit/OkHttp Client. If you have existing interceptors, you probably want Moesif’s interceptor last in the chain to ensure it captures the HTTP call just before going over the wire. See more Info on using OkHttp Interceptors


OkHttpClient client = new OkHttpClient.Builder()
    .addInterceptor(new MoesifOkHttp3Interceptor())

4.a If using Volley:

Pass in a new MoesifOkHttp3Stack object when creating Volley’s request queue. See more info on setting up volley


    RequestQueue queue = Volley.newRequestQueue(myContext.getApplicationContext(),
                                                new MoesifOkHttp3Stack());

Configuring using OkHttp2:

Follow the previous configuration steps, except a few changes:

1. Import moesif-android-okhttp2 instead

repositories {
    maven { url "" }

dependencies {
    compile 'com.moesif.moesif-android:moesif-android-okhttp2:1.0.1'

2. Use the corresponding OkHttp2 classes instead.

2.a If using Retrofit/OkHttp3 natively:


OkHttpClient myHttpClient new OkHttpClient();
myHttpClient.networkInterceptors().add(new MoesifOkHttp2Interceptor());

2.a Or Volley:


    RequestQueue queue = Volley.newRequestQueue(myContext.getApplicationContext(),
                                                new MoesifOkHttp2Stack(new OkHttpClient()));

License info for the Android SDK

See LICENSE File for details. The MoesifOkHttp3Stack and MoesifOkHttp2Stack classes, and the entirety of the package used by this software have been licensed from non-Moesif sources and modified for use in the library. Please see the relevant source files, and the LICENSE file in the package for details.

Other Integrations

To view more more documenation on integration options, please visit the Integration Options Documentation.

Leave a Comment