Creating an application launcher icon for Android Studio

86,430

Solution 1

Here is my android-studio.desktop file. Its working after adding bash -i before program path.

[Desktop Entry]
Version=1.0
Type=Application
Name=Android Studio
Exec=bash -i "/home/user/android-studio/bin/studio.sh" %f
Icon=/home/user/android-studio/bin/studio.png
Categories=Development;IDE;
Terminal=false
StartupNotify=true
StartupWMClass=jetbrains-android-studio
Name[en_GB]=android-studio.desktop

Solution 2

This is so simple...

Go to Android Studio > Tools > Create desktop Entry

Solution 3

This has been asked before for IntelliJ. Since Android Studio is the same in this context I will link to the answer and copy it here.

https://askubuntu.com/a/272336/72597

Snippet from linked answer

[Old Answer]

Download IntelliJ IDEA CE from [www.jetbrains.com/idea/download/][3].

  1. Extract ideaIC-XX.Y.Z.tar.gz using

    tar -zxvf ideaIC-XX.Y.Z.tar.gz
    
  2. Become root.

    sudo -i
    
  3. Move the extracted folder to /opt/idea

    mv ideaIC-XX.Y.Z /opt/idea
    
  4. Create a desktop file and install it:

    gedit idea.desktop
    

    and copy the following to the idea.desktop file.

    [Desktop Entry]
    Name=IntelliJ IDEA 
    Type=Application
    Exec=idea.sh
    Terminal=false
    Icon=idea
    Comment=Integrated Development Environment
    NoDisplay=false
    Categories=Development;IDE;
    Name[en]=IntelliJ IDEA
    

    then execute the following command to automatically install it in the unity:

    desktop-file-install idea.desktop
    
  5. Create a symlink in /usr/local/bin using

    cd /usr/local/bin
    ln -s /opt/idea/bin/idea.sh
    
  6. For idea icon to be displayed in dash, idea icon can be added as

    cp /opt/idea/bin/idea.png /usr/share/pixmaps/idea.png
    

That's it. Now, you can launch IntelliJ from Ubuntu dash.

Note that there is an updated version of this answer and I suspect that it might apply to android studio as well.

Solution 4

I had the same problem with Android Studio on Ubuntu 14.04. Since Android Studio is a customized version of IntelliJ IDEA, I searched for similar problems with creating a Launcher entry for IDEA on Stack Overflow and I found this question:

Intellij launcher doesn't work on unity?

Two of the answers to that question mention that the Launcher entry doesn't work because it can't find the JDK installation directory. That location can be defined system-wide in /etc/environment or per-user in their .bashrc file. I think the users that report that their Android Studio desktop entry works without any tweaking are probably using an system where the JDK location has been set on a system-wide basis.

If you don't have permission to edit /etc/environment or prefer to keep your customizations local to your login, it's still an easy fix.

  • create an Android Studio .desktop file for your login by using Studio's Tools -> Create Desktop Entry... menu item
  • define the location of the JDK by setting the JAVA_HOME or JDK_HOME environment variable in your .bashrc file
  • edit the Android Studio .desktop file and add bash -i to the beginning of the Exec statement.

The bash -i creates a new shell that first reads your .bashrc file to get the value of the Java environment variable and then executes the studio.sh script to run Android Studio using that value.

Here's an example of that edited line:

Exec=bash -i "/<path-to-android-studio>/android-studio/bin/studio.sh" %f

If the Android Studio icon doesn't appear in the Launcher:

  • run the studio.sh script in a terminal window to start Android Studio. Unity will pickup the values defined in the .desktop file
  • when the icon shows up in the Launcher, you can right-click on it and choose `Lock to Launcher' as usual.
Share:
86,430

Related videos on Youtube

jayant
Author by

jayant

Nothing special

Updated on September 18, 2022

Comments

  • jayant
    jayant over 1 year

    I currently launch android studio by going to /path-to-android-studio/bin and running ./studio.sh and it works fine.

    However, I want to create a launcher on the Dash and side menu for launching it easily.

    After going through some other questions like this, I first tried the Tools > Create Desktop Entry method. It did create an entry on the dash, but somehow Android Studio does not launch by clicking on it. If it's of any help, I am pasting the jetbrains-android-studio.desktop entry this method created in the /usr/share/applications directory:

    [Desktop Entry]
    Version=1.0
    Type=Application
    Name=Android Studio
    Icon=/home/jayant/Android/android-studio/bin/androidstudio.svg
    Exec="/home/jayant/Android/android-studio/bin/studio.sh" %f
    Comment=Develop with pleasure!
    Categories=Development;IDE;
    Terminal=false
    StartupWMClass=jetbrains-android-studio
    

    When this didn't help, I deleted the above mentioned .desktop entry and tried the method mentioned in this blog post, which required me to create the following jetbrains-android-studio.desktop file and paste it in /home/jayant/.local/share/applications directory

    [Desktop Entry]
    Version=1.0
    Type=Application
    Name=Android Studio
    Exec="/home/jayant/Android/android-studio/bin/studio.sh" %f
    Icon=/home/jayant/Android/android-studio/bin/idea.png
    Categories=Development;IDE;
    Terminal=false
    StartupNotify=true
    StartupWMClass=jetbrains-android-studio
    

    This also created an icon in my Dash but Android Studio refuses to launch with this also. Is there something I am doing wrong? I just want a simple launcher icon for Android Studio on my dash! I am using Ubuntu 14.04.

  • jayant
    jayant about 9 years
    I now have the exact same file with all the right paths. It's still not working. Which ubuntu version are you using? Also, can you share what permissions are for the .desktop file? And did you add anything in your PATH env variable for this to work?
  • theDistantStar
    theDistantStar about 9 years
    @jayant I created the file on editor, it got execute permission and using terminal as root I moved it into the /usr/share/applications directory. I have added this PATH=$PATH:/home/user-name/android-studio/bin/ to the end of ~/.bashrc file, thats for the command studio.sh in the terminal. Does your JAVA_HOME variable(echo $JAVA_HOME) gives proper result?
  • jayant
    jayant about 9 years
    I did not had JAVA_HOME set. But even after setting that to the correct path, the launcher is still not working. Are you using ubuntu 14.04?
  • theDistantStar
    theDistantStar about 9 years
    Yes mine is 14.04. You may have already tried this, if not follow this steps and lets hope it works- 1. Delete all the .desktop file of android-studio you created/moved to the /usr/share/applications directory. 2. Remove jetbrains-android-studio.desktop in your ~/.local/share/applications. 3. RESTART computer 4. Make sure echo $JAVA_HOME prints, if not add the path to ~/.bashrc 5. Create the .desktop file using any text editor. 6. Give execute permission to file 7. Move the file to usr/share/applications as root 8. With all hopes click on the studio icon in usr/share/applications
  • jayant
    jayant about 9 years
    Thanks for following through. Tried all the steps. Still not working. Can't find anything in the logs. It's really frustrating!
  • Daniel
    Daniel about 9 years
    @jayant: Instead of .bashrc you should use .pam_environment. "Shell config files such as ~/.bashrc, ~/.bash_profile, and ~/.bash_login are often suggested for setting environment variables. While this may work on Bash shells for programs started from the shell, variables set in those files are not available by default to programs started from the graphical environment in a desktop session."
  • androidevil
    androidevil almost 9 years
    same problem here man. really this is very frustating. i've googled a lot, and saw many answers in SO and here, and anything works. did you find a solution?
  • jayant
    jayant over 8 years
    Thanks. Adding bash -i in Exec solved the issue
  • Napolean
    Napolean almost 8 years
    Shortcut appeared and worked in case of dash but no shortcut on desktop.
  • Skylar Ittner
    Skylar Ittner over 5 years
    @Napolean cp /usr/share/applications/jetbrains-studio.desktop ~/Desktop/
  • nhp
    nhp over 4 years
    You also need to chmod +x for that file in order to execute