Adding Android Studio to your Applications Launcher and Favorites Bar in Ubuntu
I use Android Studio on my Ubuntu laptop. And on UNIX systems, the Android Studio installation is simply a tarball file that you unpack to a particular directory. To run it, you run the shell script
Well that’s nice, but I would rather have it be an icon I can click from my Applications Launcher on Ubuntu. Basically something that would look like this:
After a good ole’ Internet search, I found out how to do it on Ubuntu’s Help site: specifically this article on adding .desktop files and Unity Launchers. The main thing you need to do is create a .desktop text file describing what your launcher icon will look like and the command it will execute, and then place it in either
~/.local/share/applications (if you only want it available for you) or
/usr/share/applications (if you want it available for all users). That article lists the format of the .desktop file, as well as three methods for installing it for use:
- Manually copy to one of the …/share/applications directories I just mentioned.
- Use the GUI
- Use the command-line
For my case, for Android Studio, here is the .desktop file I created (called
Comment=Launches Android Studio
Note that I decided to set Terminal=true because, even though it would pop up an extra terminal, I wanted to see any exceptions that would be logged in case of crashes. But that’s up to one’s personal taste.
I then ran
desktop-file-validate android-studio.desktop to confirm there were no errors with my file (although according to the above article sometimes this command can report “false errors”). After doing that I then ran
sudo desktop-file-install android-studio.desktop to install it in my
/usr/share/applications folder. So now the launcher icon would appear in my list of Applications, like in the above screenshot.
For convenience, though, I wanted it to appear in my “favorites bar” (the one on the side/top/bottom of your Ubuntu desktop). Doing so was easy: I simply had to right-click on that icon in the Launcher and select “Add to Favorites”. And there it was (right at the bottom in this case).
One bit of weirdness, though, is that when you launch Android Studio from this favorites icon, it actually adds a second icon to the bar that looks like a duplicate of the icon you added. I believe the reason is because the shell script that runs actually kicks off a
java command, and when that java process opens up the IDE window the icon associated with that window appears in the favorites bar.
In fact, if you type
ps -ef you can see that a few processes are kicked off as a result of the
studio.sh script that is run:
my_user 125588 4398 0 01:22 pts/2 00:00:00 /bin/sh /home/my_user/android-studio/bin/studio.sh
my_user 125648 125588 99 01:22 pts/2 00:03:03 /home/my_user/android-studio/jre/bin/java -classpath /home/my_user/android-studio/lib/bootstrap
my_user 125707 125648 0 01:22 pts/2 00:00:00 /home/my_user/android-studio/bin/fsnotifier64
my_user 126017 125648 63 01:22 ? 00:01:10 /home/my_user/android-studio/jre/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-o
It may be possible to prevent this duplication from happening, maybe by having the
Exec field specify the actual underlying
java command. But I have yet to explore whether that will actually work or not. Regardless, this solution still works fine.
Now, normally you don’t have to go through all of those steps to get an application to stick to your favorites bar. Normally all you have to do is, while the application is running, right click on that icon and select “Add to Favorites” in the pop-up menu.
Unfortunately, that option was not available for Android Studio’s window, so the above method was necessary.