Friday, 1 February 2013

Getting Started with android


          Getting Started with Android
   
System Requirements:

Operating Systems:

  • Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit)
  • Mac OS X 10.5.8 or later (x86 only)
  • Linux (tested on Ubuntu Linux, Lucid Lynx)
    • GNU C Library (glibc) 2.7 or later is required.
    • On Ubuntu Linux, version 8.04 or later is required.
    • 64-bit distributions must be capable of running 32-bit applications.

Eclipse IDE:

  • Eclipse 3.6.2 (Helios) or greater
Note: Eclipse 3.5 (Galileo) is no longer supported with the latest version of ADT.
Step 1: Verify JDK is installed
        The first step is to check if you have the JDK (Java development kit) installed. If  not then
          You can download and install from oracle.com
         
Step 2: Download Eclipse
The next step is to download eclipse (the classic version is recommended). You can download it from http://www.eclipse.org/downloads
Step 3: Download the Android SDK
You can download the Android SDK from http://developer.android.com/sdk/index.html and unpack it. Note you may want to put your Android SDK in a safe spot since you’ll be using it a lot.
Once done, go to the tools folder and double click the android.bat file. This will open the Android SDK and AVD manager.



Step 4: Download Packages
Click on Available packages this will show a list of all the available Android SDK’s. Download an SDK that you want to build your app for.
To choose an SDK based on your device, go to Settings\About phone\Android version to see the version your phone is running. Then choose an SDK that is the same version as your device or earlier.

Step 5: Install ADT plug-in
Next we need to setup the ADT plug-in. To do this start eclipse go to Help > Install new software. Click Add on the top right corner

Enter the following URL: https://dl-ssl.google.com/android/eclipse/ Check developer tools, click Next, and walk through the wizard to install the tools.
Or Download ADT Plug-in from http://developer.android.com/tools/sdk/eclipse-adt.html and click Archive from Add Repository then walk through the wizard to install the tools.
After you restart Eclipse, it will prompt you for the Android SDK installation directory. Select “Use existing SDKs” and browse to the directory where you downloaded the Android SDK, and finish the wizard.
That’s it! You have successfully setup your development environment.

Hello Android!!

Assuming you have successfully installed everything, it’s time to create your first android project.
Step 1: Creating the project
  • Start eclipse
  • Go to File > New > Other > Android and select Android Project. You should see the following popup screen (yours may be slightly different or split into several steps):
·          Enter all the details as I have. Here is a brief explanation of each field:
o    Project name is the name of the directory that contains the project files (name it Quote Reader because that’s what we’ll make).
o    Build target specifies which version of Android the application is built for. I’ve selected 2.2.
o    The Application Name, Package Name are self explanatory except for the MIN SDK property. This is used for backward compatibility i.e. if your application requires a minimum api level, or is designed only to support a certain range of Android platform versions. Setting this to a value ensures that your application can only be installed on devices that are running a compatible version of the Android system.
·          Then Create New Activity Click Next.
Okay! Now that you have entered all the details press next. Eclipse will now create the project, which you can see in your project navigator.




Step 2: Understanding the project structure
        Before we get started with any code lets spend some time going through the project structure.
Here is a brief description of the folders present:
·         Source (src): This folder contains all the source files i.e. this is where all the code is.
·         Res: This is the area where you keep your images, strings and xml layouts.
·         Assets: This is another place where you can keep files. The difference between /res and /assets is that Android does not generate IDs for the assets. What this means is that to access a file in assets the developer has to provide a complete path to that file.
Now that you have a basic understanding of the project structure, let’s run the application.



Step 3: Running the application
There are two ways in which we can run the application either on an actual device or on an emulator. I will explain how to do both very briefly.
To run the application on the emulator we first need to create an AVD (Android virtual device). This is an instance of the android emulator. To do this, follow these steps:
·         Go to Window > Android SDK & AVD Manager and click New in the top right corner.
·         Enter all the required details.

  • Click on “Create AVD”, after that you can start the emulator by just selecting it from the AVD manager and clicking on start.
After the emulator starts up you can run the application that you just created. To do this right click on the project, go to Run As and select Android Application. This will launch the app on the emulator.
                   


Running the application on the device is fairly simple and requires very little effort. Here are the steps to launch an app on the device:
  • On your device, to to Settings\Application\Development and select the checkbox next to USB debugging.
  • Connect the device to your computer with a USB cable.
  • Run the project through eclipse. You will see the following popup:

  • Select the device and you’re app will be deployed.
Note: Notice that the popup above shows two options; the reason being I already have an emulator running hence I need to choose where to deploy the app i.e. either on the emulator or the device.


No comments:

Post a Comment