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
- Open the IDE settings and select Tools | External Tools.
- ClickÂ
+
 and fill out the form:
3. Click OK and apply the changes.
Customize Toolbar
- Open the IDE settings and select Appearance & Behavior | Menus and Toolbars.
- 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