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

,

Reap the benefits of Android Studio

Most of Android engineers use Android studio as their IDE and every new version of AS release we get many efficient features that we miss to use which can help to code and debug efficiently.
Watch Video

Reap the benefits of Android Studio

Sweety Bertilla
Principal Engineer
Comcast

Reap the benefits of Android Studio

Sweety Bertilla
Principal Engineer
Comcast

Reap the benefits of Android Studio

Sweety Bertilla
Principal Engineer
Comcast

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
Today, I will share my recent experience of not reading the documentation 📖carefully about…
READ MORE
blog
Software projects rarely work in isolation. Projects often rely on reusable functionality from libraries.…
READ MORE
blog
READ MORE

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

Menu