Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fandroid%2Fgradle-plugin.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fuser-guides%2Frum%2Fsdk-installation%2Fandroid%2Fgradle-plugin.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# Coralogix Gradle Plugin

The **Coralogix Gradle Plugin** enables automatic network instrumentation for your Android project. It works by injecting the Coralogix interceptor into all `OkHttpClient.Builder` instances — including those created by third-party libraries — ensuring complete visibility into your app’s network traffic without manual setup.

## Overview[​](#overview "Direct link to Overview")

When applied, the plugin uses **ASM bytecode transformation** at build time to automatically attach the `CoralogixOkHttpInterceptor` to every OkHttp client.

This guarantees that all network requests are automatically traced and reported to Coralogix, providing insights into request latency, failures, and performance bottlenecks.

## Installation[​](#installation "Direct link to Installation")

Add the plugin to your project’s `build.gradle` plugin management block.

### Option 1 — Gradle Plugin Portal (Recommended)[​](#option-1--gradle-plugin-portal-recommended "Direct link to Option 1 — Gradle Plugin Portal (Recommended)")

In your **root** `build.gradle`:

```
plugins {

    id("com.coralogix.gradle.plugin") version "2.21.1" apply false

}
```

Then, apply the plugin in your **app** module:

```
plugins {

    id("com.coralogix.gradle.plugin")

}
```

### Option 2 — Using classpath dependency (Legacy)[​](#option-2--using-classpath-dependency-legacy "Direct link to Option 2 — Using classpath dependency (Legacy)")

In your **root** `build.gradle`:

```
buildscript {

    dependencies {

        classpath "com.coralogix.gradle.plugin:gradle-plugin:2.21.1"

    }

}
```

Then, apply the plugin in your **app** module:

```
apply plugin: "com.coralogix.gradle.plugin"
```

Please note that this plugin is depended on the [Coralogix Android SDK](https://coralogix.com/docs/user-guides/rum/user-guides/rum/sdk-installation/android/README.md) as the injected classes are part of it.

Note

The minimum required Coralogix Android SDK version is `2.5.4`, using the plugin with an older version would result in unexpected behavior and potentially errors.

## Configuration[​](#configuration "Direct link to Configuration")

You can configure the plugin using the `coralogix` extension in your module’s `build.gradle` file.

```
coralogix {

    enabled = true   // Enable or disable the plugin globally

    log = false      // Enable logging of transformation activity (for debugging)

}
```

| Property    | Type      | Default | Description                                                                     |
| ----------- | --------- | ------- | ------------------------------------------------------------------------------- |
| **enabled** | `Boolean` | `true`  | Enables or disables automatic OkHttp instrumentation (true by default).         |
| **log**     | `Boolean` | `false` | Prints ASM transformation logs to the console for debugging (false by default). |

## How It Works[​](#how-it-works "Direct link to How It Works")

The plugin integrates with the Android Gradle Plugin (AGP) and uses ASM to modify OkHttp’s bytecode.

During the build process:

1. The plugin scans for all classes implementing `okhttp3.OkHttpClient$Builder`.
2. It injects a static call to the bridge method `CxNetAutoAttach.attach()`.
3. The bridge automatically attaches `CoralogixOkHttpInterceptor` to any client built using that builder.

This means **every OkHttp request**, even those created deep inside third-party SDKs, will be captured and logged by Coralogix.

## Example Output[​](#example-output "Direct link to Example Output")

When `log = true`, you’ll see logs during the build indicating which variants were instrumented:

```
[Coralogix] Inject bridge in OkHttpClient.Builder.<init>

[Coralogix] Plugin enabled on variant: release
```

## 🧾 License[​](#-license "Direct link to 🧾 License")

```
Copyright (c) 2025 Coralogix

Licensed under the Apache License, Version 2.0
```
