Blog Infos
Author
Published
Topics
Published

Once, I thought what if Android Studio had a feature to quickly create any custom button in a Menu or Toolbar without plugins, so I could run a script or open a third-party tool just by clicking the button.

Since Android Studio is based on Intellij IDEA by JetBrains I found I can use the External tools feature for my purpose. It allows you to run applications locally on your computer or even applications executed on a remote server over SSH.

So, I would like to share my experience creating an external tool and linking it to a custom button.
For example, let’s consider how to check and format your code using the ktlint tool by clicking a button in the Toolbar.

First, we need to create the external tool that will run the command ./gradlew ktlintFormat

Add external tool
  1. Open the IDE settings and select Tools | External Tools.
  2. Click + and fill out the form:

 

 

3. Click OK and apply the changes.

Customize Toolbar
  1. Open the IDE settings and select Appearance & Behavior | Menus and Toolbars.
  2. In the list of available menus and toolbars, expand the Main Toolbar | Toolbar Run Actions node and click + to add a new action.

 

 

3. Add the external tool action and set an icon:

 

 

That’s it, now we have the custom button to run ktlintFormat:

 

 

And for lovers of hotkeys, it’s possible to run the external tool by adding a shortcut key:

 

 

Conclusion

I was surprised to find the feature that it’s possible easily to link a third-party tool to IDE. The ktlintFormat is just an example, you can link any other tool (run a script, open a file in an external editor, get info from a remote server, etc.) with a custom button, shortcut key, or run it before/after commit or build. That can significantly improve your development process and make it pleasant.

This article was originally published on proandroiddev.com on July 27, 2022

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

Jobs

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Compose is part of the Jetpack Library released by Android last spring. Create Android…
READ MORE
blog
Jetpack Compose Preview are great, I’ve blogged about them before and also delivered talks…
READ MORE
blog
If you are using Android Studio Jellyfish or later, you may see the Gemini…
READ MORE
blog
Today, I will share my recent experience of not reading the documentation đź“–carefully about…
READ MORE
Menu