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
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
Add the plugin to your project’s build.gradle plugin management block.
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)
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 as the injected classes are part of it.
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
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
The plugin integrates with the Android Gradle Plugin (AGP) and uses ASM to modify OkHttp’s bytecode.
During the build process:
- The plugin scans for all classes implementing
okhttp3.OkHttpClient$Builder. - It injects a static call to the bridge method
CxNetAutoAttach.attach(). - The bridge automatically attaches
CoralogixOkHttpInterceptorto 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
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
Copyright (c) 2025 Coralogix
Licensed under the Apache License, Version 2.0