Gradle Plugin

Emerge provides a fully-featured Gradle plugin to automate common tasks.

The Emerge Gradle plugin is the recommended way to integrate with Emerge on Android. It's main features are:

  • Uploading builds to Emerge for size and performance analysis.
  • Creating and maintaining a performance subproject for custom performance analysis.
  • Generating a baseline profile using Emerge's Launch Booster service.

Quick Setup

Add the Gradle plugin portal to your plugin repositories

The Emerge Gradle plugin is hosted by the Gradle plugin portal. In new projects it should already be part of the plugin repositories. If not, you'll need to add it in settings.gradle(.kts):

pluginManagement {
    repositories {
        gradlePluginPortal()
          
        // …
    }
}
pluginManagement {
    repositories {    
        gradlePluginPortal()
      
        // …
    }
}

Apply the Emerge Gradle plugin to your top-level project

In your root project's build.gradle(.kts):

plugins {
    // …
    id("com.emergetools.android") version "1.4.0"
}

// …

emerge {
    appProjectPath.set(":app") // Your application module
    apiToken.set(System.getenv("EMERGE_API_TOKEN"))
}
plugins {
    // …
    id "com.emergetools.android" version "1.3.0"
}

// …

emerge {
    appProjectPath = ":app" // Your application module
    apiToken = System.getenv("EMERGE_API_TOKEN")
}

📘

Gradle plugins are often applied and configured in the build.gradle(.kts) file of subprojects. Emerge must instead be applied to the root project, ie. the top-level build.gradle(.kts). This facilitates cross-project features like performance analysis.

appProjectPath and apiToken are required. Other configuration properties are documented in Gradle Tasks & Configuration.

Get an Emerge API token

Navigate to your profile from the Emerge web app, or open www.emergetools.com/profile.

910

Click the "Create a new API Key" button

We recommend storing this token in a secrets store, an environment variable, or a Gradle property file. The example in this guide uses the EMERGE_API_TOKEN environment variable.

👍

All done!

You're ready to start using the Emerge Gradle plugin. Read on for some commonly used tasks.

Common Tasks

The Emerge Gradle plugin creates new tasks for your projects to help with build uploads, performance analysis, baseline profile generation, and more!

Uploading a build

./gradlew emergeUploadReleaseAab

Release can be replaced with any existing variant, for example if there is an alpha variant:

./gradlew emergeUploadAlphaAab

Aab can be replaced by Apk to upload an APK instead of an AAB (not recommended):

./gradlew emergeUploadReleaseApk

🚧

Careful when uploading builds directly

Build uploads are grouped by build type (release by default). If you have automatic pipelines set up to upload builds to Emerge, uploading some separately using the same build type could interfere with alerts and results shown in the dashboard. The build type can be configured through the plugin.

emerge {
    // …
  
    buildType.set("test") 
}
emerge {
    // …
  
    buildType = "test"
}

What’s Next

Discover other Emerge Gradle tasks & configuration options.