Sunday, July 15, 2012

Android SDK on Linux Mint 13 (Maya)

In my previous blogs, I showed how to install various 'flavors' of Java on Linux Mint 13 - both 32 and 64 bits versions. Now I will show how to install and configure the Google Android SDK to be used together with Java, for Android software development.

  1. First head over to:

      http://developer.android.com/sdk/index.html

    and download the latest (as of July 2012) file:

    android-sdk_r20-linux.tgz

    IMPORTANT NOTE:
    If you are using 64-bit Linux Mint 13 you MUST download and install the 'ia32-libs' package since the Android SDK is a 32-bit application and requires the 32 bit library to operate properly. To download and install, open a terminal and execute:
       sudo apt-get install ia32-libs

  2. Start a terminal and unzip the downloaded file:

    tar xvf ~/Downloads/android-sdk_r20-linux.tgz

    This will create a new directory 'android-sdk-linux' in your home directory containing all the unzipped files. Why the home directory? The simple answer is 'to avoid file permission problems'. Note that by installing the SDK in the home directory, only the current user can access it - so security is guaranteed.

    If, however, you want the SDK to be accessed by other users, then you may have to install it somewhere else - perhaps the /opt directory. This article will not describe how to do that - it just assumes that the current user is the only one that can access the SDK.

  3. Change directory and execute the android SDK:

    cd android-sdk-linux/tools
    ./android

    TIP: You can set the PATH environment to point to your Android SDK tools directory so that you can start the 'android' program anywhere. Edit the .profile file in your home directory and add the following lines to the end of the file:

      # set PATH so it includes user's Android SDK if it exists
      if [ -d "$HOME/android-sdk-linux" ] ; then
          PATH="$HOME/android-sdk-linux:$HOME/android-sdk-linux/tools:$PATH"
      fi

    This will only take effect on the next logout/login or restart.

    The SDK Manager will start as shown in the screenshot below.



    Notice the progress bar at the bottom of the screen - this indicates that the SDK Manager is querying for updates from Google. Wait this is finished - you will then notice that it automatically selects a set of recommended packages. However it seems to have missed the 'Android SDK Platform-tools' which, according to Google, is required when you install the SDK for the first time. So place a check mark on that item by clicking in the check-box. Also de-select the item 'Google APIs' since this can only be downloaded and installed AFTER all the rest of the marked item has been installed. The final screen will look like the one shown below.



  4. Click on the 'Install 6 packages' button - a window will pop up (shown below) listing all the packages to be installed. Notice that the 'Accept' radio button is selected - so just press the 'Install' button to start the process of downloading and installing the packages. The progress bar at the bottom indicates the status of this process. Also a log screen may appear if there are problems during install - ignore the 'Stopping ADB server failed (code -1)' message if it appears on the log - this seems to be harmless.



    When install is complete, close the log windows (if open) and then place a tick mark on the 'Google APIs' item and press the 'Install 1 package' button. When the package list appears, press 'Accept', then the 'Install' button, and then wait until this package is installed. That's it - you have installed the recommended (and latest) Android packages necessary for software development. As of July 2012 this is Android 4.1(API 16) - codenamed Jelly Baby. Is it necessary to install all the other packages (API 3 to 15)? This is entirely up to you - if you really need to develop software only for an Android version, then, by all means download and install it using the SDK Manager.

  5. Now we need to set up at least one AVD (Android Virtual Device) on which you can test your developed software. The AVD is an emulator which emulates the ARM processor. To set up the AVD we need to invoke the AVD Manager which is part of the SDK Manager. Click on 'Tools' (in the menu bar) and then click on the 'Manage AVDs...' item. You will the screen as shown below.



  6. Click on the 'New' button - a new window will pop-up (see below). Give the new AVD a name - for example 'MyJellyBaby'. Select 'Android 4.1 - API Level 16' as the target for the AVD.

    Then enter the size of the SD card - I use 128 MiB which should be sufficient for testing. Leave the rest at default except for the 'Device ram size' under hardware. To make the AVD load a bit faster and if you have at least 4GB of system RAM, change the size to 768 by clicking on the default '512' and changing it to 768.

    Next to make the emulator perform even faster, enable GPU emulation by clicking the 'New...' button and then click on the double arrow on the 'Property:' button and select 'GPU emulation' from the list. Then click on the value item and change it to 'yes'.

    The final screen will look like the one shown below. Then click on the 'Create AVD' button.If there are no errors, you will see a screen like the one below. Press 'OK' - the AVD list will then show the new AVD - MyJellyBaby in this case (see figure).







  7. To start the AVD, first select it on the list, then click the 'Start' button - a window will pop-up (see below). You can set the display size and wipe the user data from here if you wish - then click on the 'Launch' button. You will see a 'Starting Android Emulator' screen (see below) and then the emulator will start loading as shown. Note the 'flashing' Android sign while the emulator is loading.







  8. While the emulator is loading (may take time depending on the RAM size set and the speed of your system CPU and GPU), a 'thank-you' windows from Google will pop-up (see below) - if you wish you can agree to send usage statistic to Google - then click on 'Proceed' to dismiss the window.



    After a while the Android 4.1 'JellyBaby' emulator will appear (see below). The emulator's screen is blank except for 3 notifications on the top right-hand screen. To 'start' the emulator for the first time, click the 'power' button on the right side (above the keyboard) to switch off and then click on it again to power on. The login screen will appear (see below) - slide (using the mouse) to unlock the device. The 'Home' help screen will appear (see below) - click on 'OK' on the help screen and the actual Home screen will be shown (see below).









  9. You can play with the emulator at this stage - close the main window when done. Then close the 'Starting Android Emulator' screen. To dismiss the AVD list, press the 'Esc' key and you will be beck at the Android SDK Manager window. Close it if you wish.
That's it - you now have a working Android SDK and you are now almost ready to start developing Android software on your Linux Mint 13. The next blog will describe installing Eclipse - a programming environment for developing Java programs - and with the help of several Google plugins for Eclipse - a programming environment for developing Android programs as well.

7 comments:

  1. I'm currently looking for lenovo s10-2 recovery disk which could restore my netbook to it's factory setting. will you able to help?

    ReplyDelete
  2. As far as I know, there is no recovery disk for the Lenovo S10-2. The One Key Recovery system (refer to the manual for details) is supplied as standard on every Lenovo S10-2 and this allows you to restore your netbook to it's factory default. Again refer to the manual on how to do this.

    ReplyDelete
  3. Can I personally contact you on this? Really need help

    ReplyDelete
  4. Being relatively new to Linux I made the complete switch from Windows 7 to Linux Mint 13 and am not regretting it one bit. I did all of my developing mainly in Windows before and Linux has just opened my eyes to a whole new level of it. This guide is awesome and I can't thank you enough for the instructions on setting the Path correctly. It was giving me fits not being able to access adb from anywhere. Thanks again.

    ReplyDelete
  5. Great blog posts. Thanks for the clear and detailed instructions. Not only that, but they are instructions that are in tune with the overall Linux Mint environment rather than someone that is just hacking the Linux system. Great job.

    One thing I noticed after installing the JellyBelly SDK, creating the AVD exactly as you described... while playing with the emulator, it consistently crashes when I select the "world" icon (browser) in the lower right hand corner of the home page... Is there something wrong with my install or does it happen on your as well?

    Thanks

    ReplyDelete
    Replies
    1. No, the crash does not occur on mine. There could be various reasons why the crash occured - one of this is that the emulator itself is faulty (corrupted?). Try deleting the emulator and re-creating it.

      Delete
  6. I wanted to take the time out to thank you for this it helped me immensely in getting started. I had issues installing SDK in Ubuntu 12.04 this was nice! I made the change to mint and I really appreciate you teaching a man to fish as well with your explanation.

    ReplyDelete