Bytecode Transformations: Exploring new AGP APIs for instrumenting your app
summary
Explains how the deprecated Transform API is replaced by the new AGP instrumentation API (available since AGP 4.2) that runs a single Gradle task, uses ASM ClassVisitorFactory + Gradle instrumentation API, and instruments dependency jars via cached artifact transforms. Shows a working example that replaces Log.d with Timber.tag(...).d across project and third-party code (Glide), details ASM MethodVisitor edits, stack tweaks (swap, invoke_static/invoke_virtual), and frame recomputation modes; claims much less boilerplate and faster, cacheable builds.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:07Error monitoring setup
- 3:38Meta programming approaches
- 6:30Transform API overview
- 9:22Transform API limitations
- 11:07New instrumentation API
- 13:55Instrumentation API code
- 15:01ASM library basics
- 16:51JVM bytecode crash course
- 21:28Bytecode manipulation goal
- 23:12Gradle plugin setup
- 24:41Frames computation modes
- 26:47Class visitor implementation
- 33:39Testing bytecode changes
- 34:44Gradle artifact cache tips
- 36:10R8 and debugging instructions
- 36:50ASM plugin and JADX tools
- 37:13Real-world plugin examples
- 38:15Conclusion and call to action
related talks
40mIntroduction to Bytecode Instrumentation with AGP 8
42m(Android) Transformers — Bytecode in Disguise!
43m(Android) Transformers - bytecode in disguise!
11mWhat’s new in Android Gradle plugin
21mWhat's new in Android Build
34m(Android) Transformers - Bytecode in Disguise!
55mLiving in the Matrix with Bytecode Manipulation
45mMaking Java more dynamic
