Sunday, December 28, 2014

Installing Android Studio on Ubuntu 14.04 LTS

This article will guide you on how to install Google's Android Studio and set it up properly. For those of of you wondering what is the Android Studio, it is simply the IDE (Integrated Development Environment) for the Android platform. Basically it contains all the necessary tools for developing Android software, for example, an IDE and the Android SDK tools, etc. It replaces the Eclipse-based ADT formerly used by Google.


IMPORTANT NOTE FOR 64-BIT USERS: If you are using the 64-bit version of Ubuntu 14.04 LTS, it is important to note that Android Studio requires the 32-bit libraries to run properly. Although this requirement is not clearly stated under 'System Requirements', the clue is obtained from the message 'Tested on Ubuntu® 12.04, Precise Pangolin (64-bit distribution capable of running 32-bit applications'. The standard installation of 64-bit Ubuntu 14.04 LTS DOES NOT have the capability of running 32-bit applications, instead you must manually install the necessary packages by executing the following:

  sudo dpkg --add-architecture i386
  sudo apt-get update
  sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386


First you need to download Android Studio. Point your web browser to here - click on the 'Download Android Studio' button. On the next page that appears, and under the 'All Android Studio Packages' section, click on the file for the Linux platform.The terms and conditions page will appear - if you have agreed with it, select the the radio button that says so, then click on the blue button to start the download. Save the zip file and wait for the download to finish.

Start a terminal and from your home directory, execute the following command:

  unzip Downloads/android-studio-ide-135.1641136-linux.zip

This will decompress the contents of the zip file downloaded from your Downloads directory into a new directory called 'android-studio'. To start Android Studio setup, execute the following commands, one by one:

  cd android-studio/bin
  ./studio.sh

A window similar to the one shown below will appear asking whether you would like to import any settings. If this is the first time you are using Android Studio, it will be likely that you don't have anything to import. However, if you are moving from an older version of Android Studio, you may want to keep any settings made previously - in this case specify the location of the settings and let the setup wizard do the job.



Click on the OK button to proceed. Android Studio will begin loading as shown in the figure below.


After a while, the Setup Wizard screen similar to the one shown below, will appear. Click on the Next button to continue.



The wizard will start off by trying to detect where Java is installed - if you have installed and set up Oracle's Java in /usr/lib/jvm, then the wizard will find it and the next screen shown will appear.



The Standard type of setup is already selected - this is recommended unless you want to customize the setup. Click on the Next button and the the next screen will appear.



If you are using Ubuntu 14.04 and you have Virtualization Technology (vt-d) enabled in your PC BIOS and Linux kernel, then it will be detected as shown on the wizard's screen. You can read up more on this technology at the URL shown on the screen - just remember that the web page there is for Windows only - to read more on Linux and Virtualization Technology, click here. Then click on the Next button.

The next screen that appears as shown below is where you agree to accept the license for installing Google's Android SDK. Note that this is a must and cannot be skipped if you want to develop software for the Android platform. Click on Accept and the the Finish button.


The SDK components will begin downloading as shown in the next screen.

    
Once downloading and installation is completed, a log window will appear as shown. Note that, if you are using a 64-bit Ubuntu 14.04 LTS and did not install the required 32-bit packages, an error message about being unable to create an Android virtual device will appear on the last line. Click on the Finish button.


The next screen shown is the Android Studio IDE itself (shown below). You have now successfully installed Android Studio on your Ubuntu 14.04 PC.


Notice the 'Check for updates now.' on the IDE window - click on Check and if there are any updates, a window similar to the one shown below will pop up.


Click on the Update and Restart button. Android Studio will close and the updates will begin downloading as shown.

  
Do not close the Android Studio IDE window yet. There is one more thing to do before you can start to use Android Studio. Remember that, at the moment, you have to start a terminal, change to the correct bin directory and then launch studio.sh in order to start Android Studio. Surely there must be an easier way and there is! But, in order to setup the easier way, there are several things that must be done.

The first is to create a launcher item in the Unity launcher. This is easily accomplished by right-clicking on the Android Studio icon in the launcher and click on the 'Lock to Launcher' item. The Android Studio launcher (as shown by the green arrow in the screenshot below) will then remain permanently in the launcher until you remove it - but remember that the Desktop Entry for the launcher will still need to be edited before it can work properly.

 
The second is to edit the Desktop Entry text file for the
Android Studio launcher. Launch a terminal and execute the following:

  nano .local/share/applications/jetbrains-android-studio.desktop

Remember that this command is all on one line and don't forget the dot (or period) before local - this is NOT a typo as .local is a hidden file. The contents of that file need to be edited as follows:

a)  Remove the 'Setup' from the 'Name' item.
b)  Edit the 'Exec' item to /home//android-studio/bin/studio.sh (replace with your login name - in case you forgot, this is the same login name as the 'Path' item in the previous line). Note that the unedited line is for the setup command and is rather long - make sure that you remove it completely before entering the new command.
c)  Insert a line after the 'Exec' line, and type 'Terminal=false'.

Leave the rest of the items unchanged. The final file will look something like this:


Save the file and exit nano. To test whether the launcher works, first close Android Studio and then click on the launcher - Android Studio should re-open. If not, check your Desktop Entry file again.

If you want to launch Android Studio from anywhere using 'studio.sh', it is recommended that the system wide path include the android-studio/bin. To do this, execute this command in a terminal:

  sudo nano /etc/profile

In the 'profile' file make sure to include the android-studio/bin in the PATH - for example:

  export PATH=$PATH:$HOME/android-studio/bin

Save the file and close nano. To make sure that this new path takes effect, log out and then log in again. Now you can launch 'studio.sh' in a terminal from any directory. 

That's it - you are now ready to use Android Studio for developing software on the Android platform.
    

8 comments:

  1. Thanks a lot Ridzwan. There is a slight change which had to do. I had to move the unzipped android-studio folder from my Downloads folder to the Home folder and subsequently i had to edit the desktop file accordingly. To make this easier, it is better to unzip the android-studio file directly to the Home folder instead of Downloads folder at the beginning.

    ReplyDelete
    Replies
    1. Perhaps I should have made it clearer but in my defense, I did mention in the article to "Start a terminal and from your home directory..." in order to unzip the file to the home directory. Thanks anyway.

      Delete
  2. i had a problem with permissions during my install.
    To fix i just "sudo chown -R j .android "

    i found this fix on http://stackoverflow.com/questions/28472415/i-cant-install-android-studio .

    ReplyDelete
  3. There's a way to make launch feedback work. The trick is to find a suitable string to pass to the startup notification algorithm. This can be done by running "xwininfo -all" on either the top-level window or the splash-screen when Android Studio is starting up, using the cross-hair cursor to click on the window. To make a long story short, the trick is to have the following two lines in the desktop file:

    StartupNotify=true
    StartupWMClass=jetbrains-studio

    Just in case anyone may find it useful, my full desktop file is as follows:

    [Desktop Entry]
    Encoding=UTF-8
    Type=Application
    Name=Android Studio
    Comment=Android Studio
    Icon=/opt/android-studio/bin/studio.png
    Path=/opt/android-studio
    Exec=/opt/android-studio/bin/studio.sh
    Terminal=false
    StartupNotify=true
    StartupWMClass=jetbrains-studio
    Categories=Development;

    ReplyDelete
  4. I am using ubuntu 14.04 64bit. Should I install 32 bit JAVA for Android Studio?

    ReplyDelete
  5. i have made a app 'atharva' on google playstore.
    its works on some devices and on some devices its crash. all the phones are same level API. where could be a problem ??

    ReplyDelete