Replace byte-buddy with ASM for runtime method interception#2310
Open
colinmarsch wants to merge 2 commits intomasterfrom
Open
Replace byte-buddy with ASM for runtime method interception#2310colinmarsch wants to merge 2 commits intomasterfrom
colinmarsch wants to merge 2 commits intomasterfrom
Conversation
Byte-buddy was used solely for redefining class methods at runtime (e.g., intercepting View.isInEditMode()). This replaces it with direct ASM bytecode transformation + JDK Attach/Instrumentation APIs, removing ~2 transitive dependencies. Key changes: - AgentInstaller: self-attaches via VirtualMachine to obtain Instrumentation, replacing ByteBuddyAgent.install() - InterceptorRegistrar: uses ASM ClassVisitor to rewrite method bodies and Instrumentation.retransformClasses() to apply them, replacing ByteBuddy's redefine/MethodDelegation - retransformClasses (not redefineClasses) ensures compatibility with classes already modified by build-time ASM transforms - JVM flags -Djdk.attach.allowAttachSelf=true and -XX:+EnableDynamicAgentLoading added to test tasks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
saket
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Byte-buddy (
byte-buddy+byte-buddy-agent, ~3.5 MB) was used solely for one thing: redefiningView.isInEditMode()at runtime viaInterceptorRegistrar. This replaces both dependencies with direct ASM bytecode transformation and the JDK Attach/Instrumentation APIs.Why: byte-buddy is a large, general-purpose bytecode library. Paparazzi's interception needs are minimal (replace a method body with a static delegate call), so ASM's lower-level API is a better fit — smaller dependency footprint, fewer transitive deps, and more transparent bytecode manipulation.
What changed
AgentInstaller.kt(new) — self-attaches to the current JVM viaVirtualMachine.attach()to obtain ajava.lang.instrument.Instrumentationinstance. ReplacesByteBuddyAgent.install().InterceptorRegistrar.kt(rewritten) — uses ASMClassReader/ClassWriter/ClassVisitorto rewrite target method bodies withINVOKESTATICcalls to interceptor classes. UsesInstrumentation.retransformClasses()(notredefineClasses) to apply transforms, which ensures compatibility with classes already modified by build-time ASM transforms.PaparazziSdk.kt— removedByteBuddyAgent.install()call; agent installation is now handled internally byInterceptorRegistrar.registerMethodInterceptors().PaparazziPlugin.kt— adds-Djdk.attach.allowAttachSelf=trueand-XX:+EnableDynamicAgentLoadingJVM flags to consumer test tasks (required for the JDK Attach API).libs.versions.toml/build.gradle— replacedbytebuddy-agent+bytebuddy-corewithorg.ow2.asm:asm:9.7.1.Test plan
InterceptorRegistrarTestpasses — verifies ASM-based method interception and class retransformation:paparazzi:testtests pass:sample:testDebugpasses — full end-to-end: agent install → ASM transform ofandroid.view.View.isInEditMode()→ layoutlib rendering → snapshot comparison🤖 Generated with Claude Code