AndroidStudio Plugin Dev——RemoveButterKnife design to implement[pw1]

ReomveButterKnife Plugin

This is an Android Studio plugin to help remove use of ButterKnife, we will talk about how to dev it.
GitHub addressRemoveButterKnife

What AndroidStudio Plugin is?

I think you have interested in Android Dev if you read this blog, so, AndroidStudio is our most use IDE.

What AndroidStudio Plugin is?

AndroidStudio is a Google recommend IDE for Android develop, but we also need some other function when use it, we can use plugin to add the function, such as make your AndroidStudio support vim by install a vim plugin.

We can find a magnifier in AndroidStudio’s top right, click, and input plugin, click the result, you can search and install plugin in the pop window.

How to use AndroidStudio plugin

Now, we had install the plugin, how to use it?

Simple, just follow the introduction of the plugin, such as IdeaVim, it’s active after you installed it, just input in your AS with vim way!

RemoveButterKnife’s porpuse

You may hear about ButterKnife, use it and the plugin named android butterknife zelezny, you can gen code by a few click.

But some times, we may want to remvo it from our code, it’s very boring task to delete annotation and write findviewbyid code.

So, why there can’t be a plugin to help us do this boring task?


Tools need to dev a plugin

1.An idea, because AndroidStudio is dev base on idea.


Plugin dev 101

Now we can start coding!

At first new a plugin project in your Idea.

Now right click the src file, new a Action file.

Fill some info about your plugin

Now, we have this code.

actionPerformed will invoked every time when the plugin was triggered.

Now we just finish our first plugin!

RemoveButterKnife function

Here is the RemoveButterKnife’s mainly function

1.Use to Activity/Fragment witch use ButterKnife to inject view.

2.Delete import code of ButterKnife

3.Delete butterknife annotation(@bind(

4.Gen findviewbyid code

5.Delete ButterKnife.inject(this) and some thing like this

Now, there is a sample of above function



The implement detail

Now we clear our mind and write down the implement details.

1.Record import codes line number

2.Use Regular Expressions to find annotation code record line number and gen a map with name and id.

3.Find and record ButterKnife method invode code line number.

4.Delete the code on recorded number.

5.Find oncreate/oncreateview method, gen findviewbyid under the layout set code use the map with name and id we have create at step2


To implement the function we have talk above, we use three class

1.MainAction ———— To find and record line numbers, gen map with id and name.

2.DeleteAction ———— Delete code on recorded line number

3.FindViewByIdWriter ———— Gen findviewby id code

You can find the whole code on below GitHub link

In the code, i use some idea sdk api, you can search it on google to find out what it means.

Publish your plugin to repositories

You can publish your plugin to repositories by visit This Page and register an account, then click add new plugin.

If you think my blog is make your life better, how about buy me a cup of coffee?:)(1USD)

A software developer


  1. Hello,

    Nice article, good point of focus for starter. I have a doubt here, what will be the exact output format of our plugin?

    I think, .jar file will be executable file, which needs to add into Android studio, as our custom plugin, is it right.


    1. Yes, the output is a .jar file, you could install it to the Android Studio by choose install local plugin on the plugin install page.

      And you can also upload it to the repository of jetbrain(the idea soft maker) as i mentioned on the end of article

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.