Build Tools

We have simple instructions to get up and running with the CrashlyticsKit on Ant, Maven and Gradle. If you require a custom setup, see the instructions for your build tool below.

Gradle Advanced Setup

Optimize Builds when you’re not Proguarding or using Beta By Crashlytics

The Fabric Gradle plugin generates a unique identifier so that our backend can identify your builds. This identifier is used to deobfuscate crashes and distribute the correct versions of your beta test builds. The identifier will be added to your res/values and looks like:

<string name="com.crashlytics.android.build_id">RANDOM_UUID</string>

You can speed up your debug builds by making this build ID generation only happen if the file doesn’t exist. This is on by default for Android Studio Instant Runs, which never use Proguard.

We only recommend doing this if you’re not Proguarding or using Beta by Crashlytics, otherwise your crashes may not be deobfuscated correctly. To do this, add this to your app’s build.gradle:

android {
    buildTypes {
        debug {
          // Only use this flag on builds you don't proguard or upload to beta-by-crashlytics
          ext.alwaysUpdateBuildId = false
          ...

This leaves Crash reporting and Answers analytics on for your debug builds. It’s more common to completely disable Fabric for debug builds so that the build doesn’t contribute to Crashlytics or Answers. If that’s the case, see the next section for directions on the easiest way to conditionally disable the SDK.

Disable Crashlytics for Debug Builds

If you don’t need Crashlytics crash reporting or beta distribution for debug builds, you can safely speed up your debug-builds by disabling the plugin entirely with these two steps:

First, add this to your app’s build.gradle:

android {
    buildTypes {
        debug {
          // Disable fabric build ID generation for debug builds
          ext.enableCrashlytics = false
          ...

Next, disable the Crashlytics kit at runtime. Otherwise, the Crashlytics kit will throw the following error:

com.crashlytics.android.core.CrashlyticsMissingDependencyException:

This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up`

You can disable the kit at runtime for debug builds only with the following code:

// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
    .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
    .build();

// Initialize Fabric with the debug-disabled crashlytics.
Fabric.with(this, crashlyticsKit);

Customize your build.gradle

Fabric hosts a repository for all of our artifacts. This repository is declared in a build.gradle with the following:

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

We recommend putting this snippet inside the same build.gradle where your project declares the Crashlytics dependency since Gradle searches all declared repositories for your app’s artificats. An alternative location can be within your project’s root. This will work, however, if you have multiple sub-projects that share the same root build this can increase your build time. Adding the Fabric repository definition to the root build.gradle will cause Gradle to search multiple repositiories for your desired artificats.

Once you’ve retrieved our artifact, you can avoid Gradle’s dependency resolution work by running build tasks with the --offline Gradle flag. Also, if you see the exception Could not resolve io.fabric.tools:gradle:1.+. using the --offline Gradle flag can help solve this issue.

Set Up a Library Subproject

If you want the Crashlytics Kit to be in a library your project is using instead of your project, after setting up your base project, make these additional changes. Keep the following changes in your base/build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

Then move the following lines to your library/build.gradle

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile('com.crashlytics.sdk.android:crashlytics:KIT_VERSION@aar') {
        transitive = true;
    }
}

Note

If you want Fabric.with initialized in your library instead of your project’s onCreate(), move Fabric.with into the library.

Ant Advanced Setup

Customize your setup by adding any of these locations to your POM.xml:

<property name="crashlytics.project.path" location="PROJECT.ROOT"></property>
<property name="crashlytics.manifest.path" location="MANIFEST.PARENT/AndroidManifest.xml"></property>
<property name="crashlytics.res.path" location="RES.PARENT/res"></property>

Refer to the comments at the top of the crashlytics_build.xml file, if your ant build differs significantly from those provided with the Android SDK.

Maven

Add custom paths with this snippet:

<plugin>
    <groupid>com.crashlytics</groupid>
    <artifactid>crashlytics-maven</artifactid>
    <version>1.7.0</version>
    <configuration>
            <androidManifestPath>relative/path/to/
                    AndroidManifest.xml</androidManifestPath>
            <androidAssetsPath>relative/path/to/assets
                    </androidAssetsPath>
            <androidResPath>relative/path/to/assets
                    </androidResPath>
    </configuration>
    <executions>
            <execution>
                    <id>GenerateResources</id>
                    <goals>
                            <goal>GenerateResources</goal>
                    </goals>
            </execution>
            <execution>
                    <id>CleanupResources</id>
                    <goals>
                            <goal>CleanupResources</goal>
                    </goals>
            </execution>
    </executions>
</plugin>