本项目演示了如何借助 Gradle Transform 技术对字节码进行插桩。
-
临时禁用插件
在
app模块的build.gradle文件中,先将TransformPlugin插件的应用配置注释掉:plugins { // id("TransformPlugin") } -
发布插件
执行以下命令来构建并发布 Gradle 插件 demo:
./gradlew publishAllPublicationsToMavenRepository
-
启用插件
发布完成后,取消注释
TransformPlugin配置:plugins { id("TransformPlugin") } -
运行应用
直接运行
app模块,启动后你将看到带有 “Injected By ASM” 提示的 Toast 消息,表明字节码插桩已成功应用。
This project demonstrates a Gradle plugin demo that leverages the Gradle Transform API for bytecode instrumentation.
-
Temporarily Disable the Plugin
In the
appmodule'sbuild.gradlefile, comment out the application of theTransformPlugin:plugins { // id("TransformPlugin") } -
Publish the Plugin
Execute the following command to build and publish the Gradle plugin demo:
./gradlew publishAllPublicationsToMavenRepository
-
Enable the Plugin
After the plugin has been published, uncomment the
TransformPluginconfiguration:plugins { id("TransformPlugin") } -
Run the App
Run the
appmodule. Once launched, you should see a Toast message stating “Injected By ASM”, indicating that the bytecode instrumentation was successfully applied.