How to modify bytecode using compile time in android
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}" } }
I used it in gradle and it didn't work
How did it not work?
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
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.