Android Studio as your standard diff and merge tool - 2024 Hedgehog update

1 minute read

With Android Studio Hedgehog, my now outdated blog post Android Studio as a standard diff and merge tool on the same topic unfortunately no longer works.

So here is a little update on how to use Android Studio (or IntelliJ IDEA) as a diff tool for e.g. Sourcetree.

Create command line launcher

In earlier Android Studio versions, you could create a command line launcher via the menu Tools > Create Command Line Launcher… and confirm the installation to the default location with OK.

Nowadays, you get the information that you have to create it yourself:

Android Studio Command-line Launcher Dialog

The suggested way to add '/Applications/Android Studio.app/Contents/MacOS' to the $PATH variable made the command studio available to the terminal. But Sourcetree does not read the $PATH varialbe and thus did not work with setting studio as the Diff command.

What worked, however, was to set the entire path to the studio binary so '/Applications/Android Studio.app/Contents/MacOS/studio' (note: enclosed in ' because of the space in the app name) as a diff command.

The better way: create a studio script in /usr/local/bin/

The online help mentioned in this dialog suggests creating the start script yourself. However, some details are missing in this suggested solution.

The easiest and best way I have found is to create a script file named studio in /usr/local/bin/ (or somewhere else and create a symbolic link to it) and make it executable with the chmod +x command as described in the online help.

Almost identical, but with the following content:

#!/bin/sh
open -W -nb "com.google.android.studio" --args "$@";

Info: The essential part is the -W parameter - otherwise Android Studio will start and complain that it could not find the files to compare.
Instead of the -a parameter from the online help, I prefer the -b parameter, which uses the BundleIdentifier instead of the application name to find the application to open, which is more reliable in my opinion.

Info2: You may come to the conclusion that you should add this command as a zsh function instead of creating an extra bash script file for it. But with the integration in Sourcetree you are out of luck. Since Sourcetree doesn’t read ~/.zshrc (as I said, it doesn’t read $PATH either), it won’t recognize the function definitions it contains.

With this studio script the configuration is exaclty like in the old days Android Studio as your standard diff and merge tool.