Installing the Embrace.io SDK

Installing the Embrace.io SDK

By now, you should have received a unique API key. If not, please contact us via Slack or email support@embrace.io and we’ll get you started!

The Android SDK is currently hosted on our public Maven repository on Bintray. A Bintray account is not required to download the SDK. However, the repository must be registered in your build.gradle file in order for Gradle to pull all necessary dependencies.

buildscript {
    // Register Embrace.io repository for downloading the SDK plugin.
    repositories {
        maven {
            url "http://embrace-io.bintray.com/mvn-public"
        }
    }

    dependencies {
        classpath 'embrace-io:embrace-swazzler:2.0.5'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'embrace-swazzler'

repositories {
    // Register Embrace.io repository for downloading library dependencies.
    maven {
        url "http://embrace-io.bintray.com/mvn-public"
    }
}

In order for your custom Application class to be used, it needs to be registered in the Android manifest. The manifest is also where you will be declaring your Embrace API key. This can be done by making the following changes to your AndroidManifest.xml file.

<manifest
    android:package="com.mycompany">
    <application
        android:name="com.mycompany.MyApplication" />
        <!-- The API key specific to your application. -->
        <meta-data
            android:name="io.embrace.android.embracesdk.api.key"
            android:value="<EMBRACE_API_KEY>" />
        <!-- The fully qualified class name to the auto-generated BuildConfig class.
             This value should be set to the package name defined in the manifest tag followed by ".BuildConfig".
             Note that this value is NOT the same as the application ID.-->
        <meta-data
            android:name="io.embrace.android.embracesdk.build.config"
            android:value="com.mycompany.BuildConfig" />
    </application>
</manifest>

To provide the most accurate measure of the performance of your app, it is highly recommended to initialize the Embrace.io Android SDK as early as possible. Ideally, this should be the first thing your app should do as soon as it is launched. For most typical situations, this can be accomplished by creating a custom class that extends android.app.Application and initializing Embrace within the onCreate() callback method.

package com.mycompany;

import io.embrace.android.embracesdk.Embrace;

public final class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Embrace.getInstance().start(this);
    }
}

The final step is to add the following Proguard rules to your application. These rules help us surface meaningful debugging information to you when we capture uncaught exceptions. While not absolutely critical, we highly recommend adding these rules as they will significantly improve your experience with Embrace.io.

-keep class io.embrace.android.embracesdk.** { *; }
-dontwarn io.embrace.android.embracesdk.**

-keepattributes Exceptions, InnerClasses, LineNumberTable, SourceFile
-keep class com.mycompany.BuildConfig { *; }

Congratulations! You’ve successfully integrated Embrace.io into your Android application! You’re now ready to measure the performance of your app’s startup process.