byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

How to modify bytecode using compile time in android

Open sunshaobei opened this issue 9 months ago • 4 comments

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'net.bytebuddy.byte-buddy-gradle-plugin'

android { compileSdk 35 namespace "com.example.bb" defaultConfig { applicationId "com.example.bb" minSdk 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }

compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = "17" } }

dependencies { implementation 'net.bytebuddy:byte-buddy:1.17.4' implementation libs.androidx.appcompat implementation libs.kotlin.stdlib implementation libs.material implementation libs.androidx.activity implementation libs.androidx.constraintlayout }

byteBuddy { transformation { pluginName = 'com.example.bb.LogTransformer' println "Configuring transformation for ${pluginName}" } }

sunshaobei avatar Mar 31 '25 08:03 sunshaobei

I used it in gradle and it didn't work

sunshaobei avatar Mar 31 '25 08:03 sunshaobei

How did it not work?

raphw avatar Apr 11 '25 19:04 raphw

Can't work; Plugin [id: 'net.bytebuddy.byte-buddy-gradle-plugin'] was not found in any of the following sources:

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org. BUILD FAILED in 127ms

mandagod avatar May 21 '25 07:05 mandagod

This is hard for me to comment on. I suggest to create a minimal working example based on: https://github.com/raphw/byte-buddy/tree/master/byte-buddy-gradle-plugin/android-plugin

From there, incrementally adjust to your own build.

raphw avatar May 22 '25 07:05 raphw