The inspection-gradle-plugin is a Gradle plugin that packages special-purpose inspection libraries (inspector.jar) inside of Android libraries (.aar files). These inspector JARs are used by Android Studio to provide live, detailed insights into how a library is behaving inside a running application (e.g., inspecting WorkManager‘s jobs or Compose’s layout).
The plugin automates the process of creating a self-contained inspector and bundling it into a target library's release artifact. This involves two main projects:
:work:work-inspection or :compose:ui:ui-inspection).:work:work-runtime or :compose:ui:ui).The process can be broken down into two parts:
inspector.jarThis happens within the inspector project.
ShadowDependenciesTask): The plugin finds all of the inspector project‘s transitive dependencies. It bundles their compiled code directly into a single “fat JAR” along with the inspector’s own code. Crucially, it renames the package paths of these bundled dependencies to prevent version conflicts with the app that will eventually use the target library. Note, some dependencies are dropped in the process (e.g. kotlin-stdlib), because they are expected to exist at runtime.DexInspectorTask): The resulting “fat JAR” is converted from Java bytecode into the Android DEX format, creating the final inspector.jar.inspector.jar into the AARThis happens within the target library project.
packageInspector() function is called in the target library's build.gradle to link it to the inspector project.AddInspectorJarToAarTask): When the target library's release variant is built, this task injects the inspector.jar (created in Part 1) into the /libs directory inside the final .aar file.VerifyInspectorJarPresent): A final check ensures the inspector.jar was packaged correctly..aar) file for the target library. This AAR is standard, but contains the inspector.jar inside its libs/ folder.inspector.jarThe inspector.jar is a self-contained, DEX-formatted file containing:
org.jetbrains.kotlin becomes androidx.inspection.shadow.org.jetbrains.kotlin) to guarantee that the inspector runs independently and does not create dependency conflicts within the host application.This allows Android Studio to safely load and run the inspector to provide rich debugging features for the target library.