An Intellij IDEA project that build a simple Gradle plugin for android app.
This project uses Transform and ASM to implement a gradle plugin for android app that instrument some code into onCreate method of MainActivity. Transform provides a method transform to traverse and each .class file and modify some of them. ASM gives us convenient approaches to modify a .class file, such as modify specified method, fields etc. In this project,MainActivity.class is instrumented with a new line of code, which invokes static method insertedMethod
of class tech/liutao/evaluateplugin/InsertCode
, and keep all other .class files unmodified. NOTE that class InsertCode
is NOT in this project. It's in android projects that use this simple plugin.
Open this porject with Intellij IDEA, and execute task uploadArchives by command ./gradlew uploadArchives
or double click that task in Intellij Idea. Then a repo
directory, which act as a local maven repository that holds the newly created plugin, would be generated in the root directory of this project. After this, we could build a android app to test this simple plugin, just like SimplePluginTest.
- Concrete steps about creating simple gradle plugin could be found in kind Darren's blogs.
- Different from Darren's blog. I commented the line
compile 'org.codehaus.groovy:groovy-all:2.3.11'
inbuild.gradle
file to avoid an error of duplicate groovy. The need to comment that line depends the groovy enviroment in OS.