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


    Kotlin Multiplatform Mobile Developer

    Touchlab
    Remote
    • Full Time
    apply now

    Sr. Software Development Engineer, Last Mile Driver Assistance Technology

    Amazon
    Berlin
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

,

Upgrade Android Studio experience by building your own plugins

Android Studio allows anybody to build and integrate plugins in the IDE to customize/enhance the development experience. This talk will introduce the different options for plugin development weighing in the pros and cons, and the…
Watch Video

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

Upgrade Android Studio experience by building your own plugins

Santosh Astagi
Software Engineer
Meta Platforms

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
READ MORE
blog
A while back I wrote an article about how to set up wireless ADB…
READ MORE

Leave a Reply

Your email address will not be published.

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

Menu