Showing posts with label ADT Bundle. Show all posts
Showing posts with label ADT Bundle. Show all posts

Wednesday, December 25, 2013

Starting Android Programming on Windows 7 (UPDATED)

This is an updated blog based upon an earlier blog on starting Android programming on a Windows 7 PC. It was done to reflect changes to the Java JDK, Android SDK and ADT, and the Eclipse IDE. Oracle Java has been updated to 1.70_45 while Google has created an Android ADT bundle which includes Eclipse, the ADT plugin and all other bits and pieces which are required for Android software development. This makes things easier for the developer since only 2 package types need be downloaded and installed - Oracle Java and the ADT Bundle. I also took this opportunity to include lots of screen-shots as well as revise the text of the blog.

Recently, I invested in an Android smartphone (albeit a cheap one) and wanted to write my own software for the smartphone. So I did some research via the Internet about Android software development. As usual, there were a lot of information available from the Internet, some good and some bad (as far as 'easy-to-read' and 'understandable' goes) - so I decided to write my own guide on how a beginner to Android software development can start on a Windows 7 PC. This blog covers Android software development on a 32-bit Windows 7 PC while the procedures for a 64-bit Windows 7 PC is very similar. I will also assume that the reader is familiar with software programming in general and Java in particular. No effort will be made to teach the reader how to program - so be forewarned.

Writing software for Android requires Java. So, the first thing to do is download and install the Oracle Java JDK.

  1. Open a web browser and go to here - Click on 'Download' under the JDK column - NOT the JRE column (see figure below).


         Select Java 7 JDK

    You will then brought to the download page where you first have to accept the license agreement (click on the 'Accept License Agreement) and then you have to select the correct file for your OS - in my case, it is 'jdk-7u45-windows-i586.exe' for the 32-bit Windows 7 32-bit OS. Note that that you can download and install the same 32-bit Java JDK on a 64-bit Windows 7 PC - which is highly recommended anyway.


         Download Java 7 JDK

    Click on 'Save File' when the dialog box pops up. This will take a while to finish downloading. When completed, and on the same download page, click on the demos and samples file (in my case it is jdk-7u45-windows-i586-demos.zip) to download it.


         Download Java 7 Samples & Demos

    When completed, go back to the last web page (use the browser's back key), scroll down the web page until you see Java SE 7 Documentation (see figure below) - then click on it.


         Select Java 7 Documentation

    Again you first have to accept the license agreement (click on the 'Accept License Agreement) and then click on the 'jdk-7u45-apidocs.zip' file.


         Download Java 7 Documentation

    Save this file to the same folder as the JDK you have downloaded. Again, this will take a while to finish downloading.

    Go to the folder where the downloaded Java JDK file 'jdk-7u45-windows-i586.exe' resides and double-click on it. Click 'Yes' when UAC pops up - then 'Next', 'Next', and again 'Next'. When you see the 'Successfully Installed Java SE Development Kit 7 Update 45' window, click 'Close'.

    To install the Java 7 API documents, first unzip the file (jdk-7u45-apidocs.zip in my case) to a temporary folder and then move the 'docs' folder from the temporary folder to the Java JDK folder (C:\Program Files\Java\jdk1.7.0_45 in my case). If UAC pops up, click on the 'Continue' button.

    To install the Java demo and sample files, first unzip the file (jdk-7u45-windows-i586-demos.zip in my case) to a temporary folder. This will create a folder named 'jdk1.7.0_45' in which 2 sub-folders, 'demo' and 'sample' are found. Move these 2 sub-folders to the Java JDK folder (C:\Program Files\Java\jdk1.7.0_45 in my case). If UAC pops up, click on the 'Continue' button. You now have Java JDK 7 installed.
     
  2. Windows 7 does not set the environment variable JAVA_HOME. If you plan to use a text editor and/or the command line (or with Eclipse) to develop Java programs, you have to do this manually if you want to develop Java software. Failure to do this may cause error(s) when developing and testing Java software. Also, the path variable need to include the 'bin' subdirectory of the Java JDK if the 'javac' compiler is used to compile Java software from the command line. To set these variables, follow these steps:

    1. Right-click on the 'Computer' icon on your desktop (if present) or click on the 'Start' button then right-click and select 'Properties'.
    2. Click on 'Advanced system settings' located on the left-hand column.
    3. Click on the 'Environment Variables' button.
    4. Under the System variables part, click 'New'.
    5. Enter the Variable name as JAVA_HOME.
    6. Enter the Variable value as the installation path for the Java JDK (C:\Program Files\Java\jdk1.7.0_45 in my case).
    7. Click 'OK' to set the new JAVA_HOME variable.
    8. Under the System variables part, click on the 'Path' variable already there (you may have to scroll down a bit) and the click on the 'Edit...' button.
    9. Press the 'End' key to place the cursor at the end of the line and enter the 'bin' path (preceeded by a semi-colon ';') - in my case is ';C:\Program Files\Java\jdk1.7.0_45\bin'. Press 'OK', 'OK' followed by another 'OK'.
    10. Reboot Windows 7 in order for the PC to recognize the new system variables.

    To test whether the environment variable JAVA_HOME has been set correctly, open a command window and type:

      echo %JAVA_HOME%

    If the output shows the correct path (C:\Program Files\Java\jdk1.7.0_45 in my case) then JAVA_HOME has been set correctly. If not, check that you have followed the steps (1) to (10) above correctly.

    To check whether the path has been set correctly, type:

      javac -version

    If you see 'javac 1.7.0_45' as the output line, the the path has been set correctly.  If not, check that you have followed the steps (a) to (j) above correctly. Once you have corrected the problem, and as another test that Java is working correctly, type:

      java -version

    If you see "java version "1.7.0_45"" in one of the output lines, then you have installed Java correctly.
     
  3. Writing software for Android also requires the official Android SDK, and the Eclipse IDE. Google has created a ADT Bundle to make things easier for the developer as this is the only package (it includes the essential Android SDK components and a version of the Eclipse IDE with built-in Android Developer Tools) that has to be downloaded. It contains everything a developer needs to begin developing Android applications. Open a web browser and go to here. Click on the 'Download the SDK' button on this page (see below).


         Download ADT Bundle

    On the next page, agree to the Terms and Conditions, select the correct version (32 or 64 bit), and then click on the 'Download the SDK ADT Bundle for Windows' (see below) button to start downloading.


         Select Download ADT Bundle

    Wait for the download to finish then unzip the file to the C:\Users\*username* folder (replace *username* with your own login name). Once completed, you will find a new folder labelled 'adt-bundle-windows-x86-20131030' under C:\Users\*username*.

    That's it! The IDE is already loaded with the Android Developer Tools plugin and the SDK is ready to go.
     
  4. The Eclipse executable is found in the C:\Users\*username*\adt-bundle-windows-x86-20131030\eclipse (replace *username* with your own login name) directory. It is suggested that a shortcut to the executable be made on the desktop so that Eclipse can easily started.

    Double click on the Eclipse icon to start it - if this is the first time that Eclipse is started, a default workspace needs to be specified in the windows that pops up (see below).


         Eclipse Workspace

    Put it anywhere you like - in my case I placed it under C:\Users\*username*\Projects\Android (where *username* is my own login name) and I use this as my default by selecting 'Use this as the default and do not ask again'. Click 'OK' - if this is the first time that Eclipse is started, a 'Contribute Usage Statistics' window will be displayed as shown below. Select either 'Yes' or 'No' and then click on the 'Finish' button.


         Eclipse Contribute Usage Statistics

    The Eclipse 'Welcome Screen' will be displayed as shown below. Read this and follow the links if you wish. Remember that this window can be re-displayed at any time later by selecting 'Help' and then 'Android IDE' from the menu.


         Eclipse Welcome Screen 
     
    Close the welcome screen by closing the Android IDE tab and the main Eclipse workspace will be displayed (see below).


         Eclipse Workspace
     
  5. Click on the 'Window' item on the Eclipse menu, and then select 'Android SDK Manager'. After a while, the Android SDK Manager window (shown below) will appear.


         SDK Manager Window

    Notice that both the Android SDK Tools and Android SDK Platform-tools have already been installed along with some of the files for Android SDK (API 19). If there are updates to any of the items already installed, these will be indicated as shown in the figure above. Notice the button at the lower right hand corner that says 'Install 5 packages...' - click on this button and a window (as shown in the figure below) will pop-up asking to to confirm the packages to be installed along with the acceptance of the license. Click on the 'Accept License' and then the 'Install' button. Then wait for the updated items to be downloaded and installed.


         Package Install

    When completed, you should see a screen similiar to the one below. At this point, you can select other extra packages to install. Note that you can start developing Android software for Android version 4.4 (KitKat) without installing anything else. However, if your actual Android device is not version 4.4 but a previous version, for example version 4.1.1 (JellyBean), you can download files for that version but be aware that version 4.4 (KitKat) is supposed to be backward compatible to lower versions (what this mean is that software developed using version 4.4 SDK will work on previous versions of Android).


         Updated Packages Installed

    I do encourage that the samples and documentation for Android 4.4 be downloaded and installed. To do this, place check-marks on the 'Documentation for Android SDK' and the 'Samples for SDK' files. Then click on the 'Install 2 packages...' button. The Choose Packages to Install window will pop up (see below) - select 'Accept License' followed by the Install button. The items will then start downloading - progress of the download and install process will be shown on the SDK Manager window.


         Choose Packages Window

    Once the process is completed, the SDK Manager will show something like the one shown in the figure below. Then close the SDK Manager.


         Packages Installed
     
  6. You can now set up one or more Android virtual devices (AVD) which correspond to your actual Android device(s). By doing this, you can test the developed software to see whether they work or not on the device. To do this, first click on the Window item in the menu, and then select Android Virtual Device Manager. After a while, the AVD Manager window (shown below) will appear.


         AVD Manager Window

    If this is the first time you are using the Android AVD Manager, there will be no virtual devices and the list of available AVD's will be empty. To create a new virtual device, click the 'New...' button. A window will appear in which you need specify what type of device you are going to create (see figure).


         New AVD Window

    First enter the AVD Name of the device - for example 'MyKitKat' - any name will do, as long as you remember what type of device it represent (an Android 4.4.2 KitKat device in this case).

    Next you need to specify a Device to emulate - in my case, I decided to use a 5.1" WVGA smartphone as this closely resemble the actual phone that I have in my possession. You, on the other hand, may have different Android hardware - choose one closest to the specification of your hardware.

    Next you need to specify the Target - i.e., the version of Android targeted - click on the right-hand downward arrow and click on a suitable one from the list. Note that this list will only contain all the versions that you have previously installed using the Android SDK Manager. In my example, there is only one - the Android 4.4.2 - API Level 19. The CPU/ABI will be automatically entered - in my case 'ARM (armeabi-v7a)'.

    Leave the Keyboard and Skin at the default. Then select a Back Camera to use by clicking on the right-hand downward arrow and click on a suitable one from the list. Since I have a webcam on my PC. I selected 'Webcam0'. Note that this item will not be listed if you do not have a webcam - if that is so, select 'Emulated' instead.

    Leave the RAM and VM Heap and Internal Storage values at the default values. You can, however, change to suit your preference.

    You can now specify the size of the SD card to emulate (in KiB, MiB, or GiB) - in my case I entered 200 MiB. Under Emulation Options, enable 'Use Host GPU'. Leave the rest of the fields at the defaults. The final screen will look something like the one shown below.


         New AVD Settings

    Click on the 'OK' button - the newly created virtual device will now appear in the AVD list (see below).


         New AVD Created
     
  7. To test whether the newly created virtual device works, select the device and click on the 'Start' button - the AVD Launch Options window will appear (see below).


         AVD Launch Options Window

    You are free to set any of the launch options here. For this article, we will leave the options at their defaults and click 'Launch' on the launch option window - the AVD will then start (see below).


         AVD Launching

    After a while, the KitKat Android virtual device will appear on the desktop - initially this will be blank (as shown below). This denotes that it is still loading - be patient.


         AVD Initial Screen

    The KitKat Android virtual device will change to one with a flashing 'Android' figure (see below). Wait for the flashing to stop - which may take some time to finish.


         AVD Loading

    Once the AVD has finished loading, you will be greeted with a screen similiar to the one below (a help screen for those curious) - just admire it and then click on the OK button.


         Android Initial Screen

    The home screen for Android will then appear as shown below.


         Android Home Screen

    Test the AVD on/off button by clicking on the power button (rightmost button on the top row). If this works, then the AVD's screen will go blank, signifying a power off condition (see below).


         AVD Powered Off

    Click on the power button again. The login screen (see below) will appear if everything works.


         AVD Login Screen

    Just like a real Android device, you have to slide the padlock to the right to unlock the device - do so and the home screen will reappear.


         AVD Slide To Unlock 
     
    Now click on the Apps button on the home screen (middle button on the bottom row of the home screen). Another help screen similar to the one shown below will the appear. Click on OK to dismiss this screen.


         AVD Apps Help

    The screen will now display all the apps (application software) on the AVD. You can play around with the apps later - for now let's test the Menu, Back and Search buttons.


         AVD Apps Screen

    First click on the Menu button - the screen will look like the one shown below with 2 menu items appearing from below the screen. As usual the items and number of items will change depending on the screen being viewed. Click Menu again to dismiss the menu.


         AVD Menus

    Now click on the Search key (the rightmost button which looks like a magnifying glass) and after a short delay (depending on your internet connection) the screen will look like the one below.


         AVD Search Screen

    Now click on the Back button (the one to the left of the Search button) and the home screen will re-appear. Click on the Apps button again and the apps screen will re-appear. Then click on Home button (the leftmost button which looks like a house) and the home screen should re-appear.

    Once you have tested all the buttons, you can now play with the AVD. Just remember that this is a virtual machine emulating an ARM CPU based device on an x86 PC. If you expect the virtual device to be fast, then you need to lower your expectation - try it out and see what I mean. It does, however, serves as a test bed for the applications that will be developed later. Close the AVD when done and then close the AVD Manager.

    Now that you have downloaded, installed and configured all the components for developing software on the Android platform, you can start off programming with the obligatory 'Hello World' program.
     
  8. Start Eclipse and then click on the New button found in the toolbar. In the New project window that appears next (see figure below), expand the 'Android' item by clicking on the arrow to the left of the name and selecting 'Android Application Project'. Then click Next.


         Android Application Project Selected

    Fill in the form that appears (see below) with the data shown. Note that after entering the Application Name 'My First App', the Project Name and Package Name is automatically filled in - do not change this. The 'Minimum Required SDK', 'Compile With' and 'Theme' has also been filled in with the correct data - in my case, I have only to change the Target SDK to 'API 19: Android 4.4.2'). Then click Next.


         New Android App Data

    Click Next and when the 'Configure Project' screen (see below) appears, leave everything here at their defaults.


         Configure Project

    Click Next and the 'Configure Launcher Icon' screen (see below) appears. Do not change anything here.


         Configure Launcher Icon

    Click Next and the 'Create Activity' screen (see below) appears. Again, do not change anything here.


         Create Activity

    Click Finish when the 'New Blank Activity' screen (see below) appears.


         New Blank Activity

    The main Eclipse workbench will reappear after a while (see figure below) - your first Android project has now been set up with some default files.


         Workbench With First Project

    Although it is not evident from the figure above, note that the project that was just created includes a default "Hello World" source file that allows you to immediately run the application without having to enter any lines into your project. The expected output from this project are the words "Hello world!" displayed on the device's screen. You can view the expected output by clicking on the 'activity_main' tab on the Eclipse IDE.
     
  9. Now we will test out the application on the AVD you have previously created. First, make sure that you do not have any Android device plugged into your PC (we will test it on an actual Android device later). Then click on the Run As... button (the green one with the white right-pointing arrow) in the toolbar. A Run As window will appear (see below) - select Android Application and click OK.


         Run As Window

    The program will run and the AVD login window will appear (see below) - slide to unlock and, after a while, the output of your first Android application will appear in the AVD (see below). If this the first time you are running Eclipse, you may also get an Auto Monitor Logcat window popping up as shown below. Click OK if it does.


         AVD Login Window


         MyFirstApp Output


         Auto Monitor Logcat Window

    If you press the Home button and then the Apps button, you can see that your My First App will also be listed in the available applications (see below).


         My First App Listed 
     
    Congratulations! You have just successfully tested MyFirstApp on the AVD. Close the AVD once you have finished admiring your work. DO NOT CLOSE ECLIPSE YET! We will now test out the same app on a real Android device - which I assume you already have one.

    Before you do any else, I suggest that you visit Google's Android Developer web site here (http://developer.android.com/sdk/index.html), and then click on 'Workflow' and then 'Using Hardware Devices'. Acquaint yourself with the contents that appear - it gives clear instructions on how to setup and connect a device for testing during software development.

    Note that most Android devices manufacturers have instructions on how to connect the devices to a Windows 7 computer via a USB port. I suggest that you peruse their instructions first before trying to connect the devices to the computer. In some extreme cases, the USB drivers are part of a software package (e.g., the Samsung Kies) and is not separate - the whole package has to be installed before the USB connection works correctly.
     
  10. Install the necessary Windows 7 USB drivers before trying to connect the Android device to the computer. Either follow the device manufacturer's instructions (first choice) or follow the instructions here http://developer.android.com/tools/extras/oem-usb.html if you have any Google devices.

    Note 1: If you have a Nexus device that is not listed, try the Nexus (generic) driver first.

    Note 2: If you cannot find the C:\Users\*username*\adt-bundle-windows-x86-20131030\sdk\extras\google\usb_driver\ directory, then the Google USB Driver package has not been installed into the SDK. Use the SDK Manager (Eclipse >> Window >> Android SDK Manager) to mark and install the Google USB Driver package.
     
  11. Make sure that USB debugging is enabled on your device - the settings can normally be found at Settings >> Developer options but may vary from device to device, but it is always located in Settings.

    Connect your Android device to the computer via a USB cable. You may get one or more messages about the drivers being installed and the installation has been successful. If the instllation failed, do not go any further until you have resolved this - the USB driver MUST be installed in order for you to test developed applications on your device.

    Open the Windows Explorer and navigate to C:\Users\*username*\adt-bundle-windows-x86-20131030\sdk\platform-tools\ directory and Shift-right-click on it and select 'Open command window here'. Then execute the following command in the window:

      adb devices

    If your Android device has been connected correctly, you should see something like this (the numbers to the left may be different from that shown):

      List of devices attached
      0123456789ABCDEFG     device


    Close the command window.
     
  12. Click on the Run button on Eclipse and a Device Chooser window (shown below) will pop up. Select the device and click OK.


         Device Chooser Window
    After a brief period, the application will run and the same output as before will appear on the device (see below). If you select Apps on your device, MyFirstApp will also appear in the Applications list of the device.


         Hello World on Device

    Double Congratulations! You have just successfully tested MyFirstApp on the AVD as well on an actual Android device.
In this blog, a lot of features on Java, Android SDK and Eclipse were not explained. If this is the first time you are trying all of the said tools, then you need spend some time to familiarize yourself with them. Documentation on all the tools are available from the Internet, so look for them and read, read, read ... and then try out the tools. Don't be afraid of making mistakes ... it's the only way to learn. Good luck!

Thursday, December 20, 2012

Google Android ADT On Linux Mint 13 (Maya)

Recently I had to task of assembling a PC and then installing the OS and other software on it for a colleague. He had also expressed his desire to start developing Android software on that PC - so, he also asked me to set it up as a development system as well.

I will not bore the readers on how I assembled the PC and installed Linux Mint 13 OS with MATE on it - suffice to say that everything works!. I now realized that I have the perfect opportunity to update my blog on Android software development with Linux Mint 13 using the latest Google ADT (Android Development Tools) bundle - which also includes the latest Android SDK and a pre-configured Eclipse IDE, using my colleague's PC. So this whole blog is on that subject - hopefully it will be of use to anyone who, like my colleague, is about to start developing Android software on a brand new PC.

Of course, the first task would have to install a Java JDK on the PC - but which Java - OpenJDK or Oracle's Java? And which version 6 or 7? Based on my past experience, I decided to go with OpenJDK 6 as I do not see any advantage of having all the 'flavors' of Java on my colleague's PC - it will only complicate matters.

These are the steps I used to set up the PC into an Android development system:

  1. Open Synaptic (Menu >> Administration >> Synaptic Package Manager), enter your password for Authentication, click Close on the Quick Introduction window (if it appears) and you will be at the Synaptic main window (see below).
     
    Synaptic intro window
     
    Synaptic main window
     
  2. In the Quick filter field, enter 'openjdk' and the package windows will show all the possible entries for this item (see below).

    Synaptic openjdk search
     

    Mark additional
     

    Mark all the packages listed below for installation (including any other additional items required):

       openjdk-6-jdk
       openjdk-6-demo
       openjdk-6-doc
       openjdk-6-dbg
       default-jdk
       default-jdk-doc
     

    Click on the Apply button to start installing all the packages - be patient as it will take some time for the download and install process to finish.
     
  3. To verify that the Java JDK has been successfully installed, open a terminal (Menu >> Accessories >> Terminal) and enter the following command:

      java -version

    You should get something like the following output:

      java version "1.6.0_24"
      OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.04.1)
      OpenJDK Server VM (build 20.0-b12, mixed mode)
     

    Do not close the terminal yet - you will need it later. Now that Java has been installed, the next task is to download and install the ADT Bundle from Google - follow the steps below.
     
  4. The ADT Bundle can be found here (http://developer.android.com/sdk/index.html). Since my colleague's PC is a 32-bit one, I selected 'adt-bundle-linux-x86.zip' to download. If you are using the 64-bit version of Linux Mint, make sure that the 'ia32-libs' package has already been installed, then download the 'adt-bundle-linux-x86_64.zip' file.
     
  5. Now unzip the downloaded file (normally to the 'Downloads' folder), by executing the following command in the terminal.

      unzip ~/Downloads/adt-bundle-linux-x86.zip
    or
      unzip ~/Downloads/adt-bundle-linux-x86_64.zip

    This will create a new folder 'adt-bundle-linux-x86' (or adt-bundle-linux-x86_64) in your home directory which will contain all the unzipped files. Under the 'adt-bundle-linux-x86' folder, there will be 2 sub-folders, one called 'eclipse' (which contains the Eclipse IDE) and the other called 'sdk' (which contains the Android SDK).
     
  6. The Eclipse IDE can be started in a terminal by executing:

      cd adt-bundle-linux-x86/eclipse
      ./eclipse
     

    A much better way is to create a program launcher on the desktop by first right-clicking on the desktop, and then clicking on the 'Create Launcher...' item. A 'Create Launcher' window will appear (see screen-shot below) - fill in the 'Name:', 'Command:' (browse to /home/(username)/adt-bundle-linux-x86/eclipse/) and 'Comment:' as shown. The Eclipse icon will be used by default. Click 'OK' to create the launcher - it will appear on the desktop. Double-click on it to start Eclipse.

    Create Eclipse launcher
     
  7. Since this is the first time Eclipse is started, it will prompt you for a workspace directory (see below) - I use '/home/(username)/Projects/Android/' (where username is my login name) but you can place it anywhere you like or accept the default of /home/(username)/workspace. You can also set this as the default and not ask again - then click 'OK'.

    Set Eclipse workspace

    You may see a screen like the one shown below asking you to contribute usage statistics - choose 'Yes' or 'No' and click on the 'Finish' button.

    Usage stats window

    The Eclipse IDE will then be displayed (see below) with a welcome message from Google - close this tab when you have finished reading it.

    Eclipse welcome screen

    The main workbench of Eclipse (see below) will now be displayed.

    Eclipse main workbench screen
     
  8. Note that Eclipse is already loaded with the Android Developer Tools plugin and the SDK is ready to develop Android software. However, we will tweak it a bit here. Click on the Window item in the menu, and select Android SDK Manager. After a while, the Android SDK Manager window (shown below) will appear. I have resized this window to show all the items.

    SDK manager screen

    Notice that both the Android SDK Tools and Android SDK Platform-tools have already been installed along with some of the files for Android SDK (API 17). You can, at this stage, download and install the rest of the files like Documentation for Android SDK, Samples for SDK, Google APIs and Sources for Android SDK but all the files needed to start developing Android software has already been installed. I do encourage, however, that the samples and documentation be downloaded and installed.

    To do this, place checkmarks on the 'Documentation for Android SDK' and the 'Samples for SDK' files. Then click on the 'Install 2 packages...' button. The Choose Packages to Install window will pop up (see below) - select 'Accept All' followed by clicking on the Install button. The items will start downloading - progress of the download and install process will be shown on the SDK Manager window. Once the process is completed (the status bar at the bottom will show 'Done loading packages'), close the SDK Manager.

    Install packages screen
     
  9. You can now set up one or more Android virtual devices (which correspond to your actual Android device(s)) so that you can test the developed software to see whether they work or not on the device.

    Click on the Window item in the menu, and select Android Virtual Device Manager. After a while, the AVD Manager window (shown below) will appear.

    AVD manager window

    If this is the first time you are using the Android AVD Manager, there will be no virtual devices and the list of available AVD's will be empty. To create a new virtual device, click the 'New...' button.

    A window will appear in which you need specify what type of device you are going to create(see below). First enter the AVD Name of the device - for example 'MyJellyBean' - any name will do, as long as you remember what type of device it represent (an Android 4.2 Jelly Bean device in this case).

    New AVD window

    Next you need to specify a Device to emulate - in my case, I decided to use a 7" WSVGA Tablet as this closely resemble the actual tablet that I have in my possession.

    Next you need to specify the Target - i.e., the version of Android targeted - click on the right-hand downward arrow and click on a suitable one from the list. Note that this list will only contain all the versions that you have previously installed using the Android SDK Manager. In my example, there is only one - the Android 4.2 - API Level 17. The CPU/ABI will be automatically entered - in my case 'ARM (armeabi-v7a)'.

    Leave the Keyboard and Skin at the default. Then select a Front Camera to use by clicking on the right-hand downward arrow and click on a suitable one from the list. Since I have a webcam on my PC. I selected 'Webcam0'. Note that this item will not be listed if you do not have a webcam - if that is so, select 'Emulated' instead.

    For Memory Options and if you have enough RAM on your system, I suggest that you increase the RAM to greater than 768 MiB. Leave the VM Heap and Internal Storage values at the default.

    You can now specify the size of the SD Card to emulate (in KiB, MiB, or GiB) - in my case I entered 128 MiB. Under Emulation Options, enable 'Use Host GPU'. Leave the rest of the fields at the defaults. The final screen will look something like the one shown below.

    New AVD settings

    Click on the 'OK' button - the newly created virtual device will now appear in the AVD list (see below).

    New AVD created
     
  10. To test whether the newly created virtual device works, select the device and click on the 'Start' button - click 'Launch' on the Launch Option window that appears next (see below). The starting emulator window will then be displayed (see below). If you see the 'Warning: No DNS servers found' message like the one shown, just ignore it for now - it will be fixed later.

    New AVD start
     
    AVD launch options
     
    AVD starting window
     
    After a while, the Jelly Bean Android virtual device will appear on the desktop with a flashing 'Android' figure (see below). This denotes that it is still loading - be patient.
     
    AVD loading
     
    Once the AVD has finished loading, you will be greeted with a screen similiar to the one below - just click on the OK button and the home screen will appear.
     
    AVD loaded
     
    AVD home screen
     
    Test the AVD on/off button by clicking on the power button (rightmost button on the first row). If this works, then the AVD's screen will go blank, signifying a power off condition (see below).
     
    AVD off

    Click on the power button again. The login screen (see below) will appear if everything works.
     
    AVD login screen

    Just like a real Android device, you have to slide the padlock to the right to unlock the device - do so and the Home screen will reappear.
     
  11. Notice that both the 'Hardware Buttons' and the 'DPAD' on the Jelly Bean AVD has not been enabled. This means that the Home, Menu, Back and Search buttons (the second row of buttons on the AVD) as well as the DPAD (the navigation pad on the AVD) cannot be used at the moment. Try pushing any of these buttons - nothing will happen. In order to activate this (along with fixing the no DNS servers found message), follow the steps below:
     
    1. Close the AVD.
    2. Close the starting emulator window.
    3. Close the AVD Manager.
    4. Close Eclipse ADT.
    5. Open a terminal and execute:
           nano .android/avd/(avdname).avd/config.ini
      where (avdname) is the name of the AVD created.
    6. Change the line that reads hw.dPad to 'yes' instead of 'no'.
    7. Change the line that reads hw.mainKeys to 'yes' instead of 'no'.
    8. Save the changes and exit the editor.
    9. While in the terminal, execute:
         sudo dpkg-reconfigure resolvconf
      Select 'Yes' when prompted.
      NOTE: This will fix the 'Warning: No DNS servers found' message during the starting of the AVD. You will also be able to access the Internet in the AVD after this fix.
      Reboot the PC to make the changes.
    10. Start Eclipse ADT again.
    11. Start the AVD Manager again.
    12. Start the AVD (MyJellyBean in this example).

    Notice that the message 'Warning: No DNS servers found' will no longer appear during the start of the AVD. You should also see the AVD look like the one below (after loading and unlocking) - notice that both the Hardware Buttons and DPAD has been enabled.
     
    Fixed AVD home screen

    You can now play around with the AVD - close the AVD when done and then close the AVD Manager. Just remember that this is a virtual machine emulating an ARM CPU based device on an x86 PC. If you expect the virtual device to be fast, then you need to lower your expectation - try it out and see what I mean. It does, however, serves as a test bed for the applications that will be developed later.

    Now that you have downloaded, installed and configured all the components for developing software on the Android platform, you can start off programming with the obligatory 'Hello World' program.
     
  12. Start Eclipse (if not started) and then click on the New button found in the toolbar. In the New project window that appears next (see figure below), expand the 'Android' item by clicking on the arrow to the left of the name and selecting 'Android Application Project'. Then click Next.

    Start new project
     
    New Android app project
     
  13. Fill in the form that appears (see below) with the data shown. Note that after entering the Application Name 'My First App', the Project Name and Package Name are automatically filled in - do not change these. The 'Minimum Required SDK', 'Compile With' and 'Theme' has also been filled in with the correct data - in my case, I have only to change the Target SDK to 'API 17: Android 4.2'). Then click Next.

    New Android app data

    Click Next when the 'Configure Project' screen (see below) appears, i.e., leave everything here at their defaults.

    Configure project

    Click Next when the 'Configure Launcher Icon' screen (see below) appears.

    Configure launcher icon

    Click Next when the 'Create Activity' screen (see below) appears.

    Create activity

    Click Finish when the 'New Blank Activity' screen (see below) appears.

    New blank activity

    The main Eclipse workbench will reappear after a while (see figure below) - your first Android project has now been set up with some default files.

    First project workbench

    Note that the project that was just created includes a default "Hello World" source file that allows you to immediately run the application without having to enter any lines into your project.
     
  14. Now we will test out the application on the AVD you have previously created. First, make sure that you do not have any Android device plugged into your PC (we will test it on an actual Android device later). Then click on the Run button (the green one with the white right-pointing arrow - not the one with the red toolbox) in the toolbar.

    A Run As window will appear (see below) - select Android Application and click OK.

    Run As window

    The program will run and the AVD login window will appear (see below) - slide to unlock and, after a while, the output of your first Android application will appear in the AVD (see below). If this the first time you are running Eclipse, you may also get an Auto Monitor Logcat window popping up as shown below. Click OK if it does.

    AVD login window
     
    AVD logcat window
     
    MyFirstApp output

    If you press the AVD's 'Home' key and then the 'Applications' icon, you can see that your My First App will also be listed in the available applications (see below).
     
    MyFirstApp listed

    Congratulations! You have just successfully tested MyFirstApp on the AVD. Close the AVD once you have finished admiring your work. DO NOT CLOSE ECLIPSE YET! We will now test out the same app on a real Android device - which I assume you already have one.

    Before you do any else, I suggest that you visit Google's Android Developer web site (http://developer.android.com/sdk/index.html), and then click on 'Tools' and 'Workflow' and finally 'Using Hardware Devices'. Acquaint yourself with the contents that appear - it gives clear instructions on how to setup and connect a device for testing during software development. The required steps for Linux Mint 13 are replicated here for your convenience.
     
  15. Open a terminal and execute:

       sudo nano /etc/udev/rules.d/51-android.rules

    This will open a blank file in which you need to enter the following (all in one line):

      SUBSYSTEM=="usb", ATTR{idVendor}=="4-digit-number", MODE="0666", GROUP="plugdev"
     

    Replace the idVendor with a 4-digit hex number for your device - the web-page mentioned above has a list of the vendor's IDs listed there.  Find the id for the vendor of your Android device on the and enter it into the file. Save and close the file. Then execute the command:

      sudo chmod a+r /etc/udev/rules.d/51-android.rules

    As an example, for my Samsung Galaxy Tab 7.7 Tablet, I looked up the idVendor and found it to be 04e8 hex. So the line I entered looks like:

      SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev"
     
  16. Make sure that USB debugging is enabled on your device (your real Android device - not the AVD) - the settings can normally be found at Settings >> Developer options but may vary from device to device, but it is always located in Settings.
     
  17. Power on your Android device, unlock it, and the connect the device to the PC via a USB cable. You may get one or more windows pop-up asking you what to do - select 'Do nothing' in all cases and then press OK. You may also get an error message saying that Linux Mint is unable to mount the Android device - click OK to dismiss the message, i.e., we will ignore it.

    Now execute the following commands on the open terminal:

      cd adt-bundle-linux-x86/sdk/platform-tools
      ./adb devices
     

    If your Android device has been connected correctly, you should see something like this:

      List of devices attached
      464119060136df1f    device
     

    Then close the terminal.
     
  18. Click on the Run button on Eclipse and a Device Chooser window (shown below) will pop up. Select the device and click OK.

    Device chooser

    After a brief period, the application will run and the same output as before will appear on the device. MyFirstApp will also appear in the Applications list of the device.

    NOTE 1: If nothing happens when you press the Run button, and error messages are displayed in Eclipse, starting with "The connection to adb is down, and a severe error has occured." then you need to perform the following steps to restart the adb.

    1. Close the Eclipse if it is running.
    2. Start a terminal and execute the following commands:

       cd adt-bundle-linux-x86/sdk/platform-tools
       ./adb kill-server
       ./adb start-server


      If you see the message 'daemon started successfully' on the terminal then the adb has been restarted successfully, else try again. Close the terminal after the adb has been restarted successfully.
    3. Start Eclipse again.
    4. Run the application again. It should run now.
        
    NOTE 2: If you are, like me, an Android developer developing software on different OS platforms (e.g., Linux, Windows, etc), you are likely to run into a situation where Eclipse complains that it cannot run the app because of an existing app on the device with the same name but have a different signature. The error message also suggest that the existing app on the device be removed - so just un-install the app and try running the project again. It should work now.

    Double Congratulations! You have just successfully tested MyFirstApp on the AVD as well on an actual Android device.
     
One last word - my colleague was extremely pleased with the new PC and is well on the way to becoming a productive (and hopefully, prolific) Android programmer.