Introduction to Bytecode Instrumentation with AGP 8
summary
AGP 8 provides an official bytecode instrumentation API that hooks Gradle variants to ASM via the Android components block and replaces the old Transform API; the demo builds a Gradle plugin that uses ASM MethodVisitor and kotlinx.metadata to detect Kotlin data classes, find constructor parameter indices for a custom @Redacted annotation, rewrite the generated toString bytecode (removing getfield/aload and inserting LDC asterisk constants), and add a marker annotation — the example compiles and produces a UI showing redacted fields.
AI-written summary · about
chapters (16)
- 0:00Welcome
- 1:15Bytecode instrumentation
- 2:58Why manipulate bytecode
- 5:03Android compilation pipeline
- 7:08AGP 8 instrumentation API
- 9:12Setup instrumentation transform
- 13:28Live demo
- 16:38Sample app demo
- 18:02Project structure & Gradle
- 20:52Visitor factory
- 24:22Class visitor logic
- 28:13Constructor parameters
- 31:00Rewriting toString
- 37:17Finalizing transformation
- 38:41Running transformed app
- 39:21Resources & closing
related talks
39mBytecode Transformations: Exploring new AGP APIs for instrumenting your app
21mWhat's new in Android Build
42m(Android) Transformers — Bytecode in Disguise!
26mBuild-Time Auto-Instrumentation in Android
55mLiving in the Matrix with Bytecode Manipulation
45mMaking Java more dynamic
11mWhat’s new in Android Gradle plugin
39m{ Android | Kotlin } Gradle Plugin in 2026 — Preparing for AGP 1…
