Is there a way to transform/modify classes and methods that are annotated by a custom annotation? #bytecode-manipulation (but for dex)
What's the best way to do it?
Proxies are not the appropriate way for what I am looking for.
Dex-file base manipulation is possible but very complex and there is almost no good tooling.
Instead, you should instrument your code during build when it is still represented as class files. There are various tools for that. I have written a tool called Byte Buddy that allows you to run code during build by either using the Maven or Gradle plugin.
In order to change a class, you have to implement the Plugin
interface of the library which allows you to specify what class you want to change and how you want to change it. Byte Buddy inlines all the class such that you do not need to create a runtime proxy.
For Gradle, you have to create a configuration referencing your plugin code:
configuration {
myPlugin
}
dependencies {
myPlugin "my:plugin:1.0"
}
byteBuddy {
transformation {
plugin "pkg.MyPluginImpl"
classpath configuration.myPlugin
}
}
I assume that is what you use giving you developing for Android.