November 5, 2010

First android app - HelloAndroid

Once the android sdk  (how to setup up android sdk ) and eclipse (how to setup eclipse for android) are set up and ready, the first android app can be created in a jiffy - its as easy as few clicks!!
Open eclipse, and from the menu select File -> New -> Android Project 



The New Android Project window opens.


Now fill in the details for Project nameApplication namePackage nameCreate Activity and Min SDK Version. Also select the Build Target as Android 2.2.
Project name is the name of the new android project. It can be "HelloAndroid".
Application name is the name of the new app - name shown in the title bar. It can be "Hello, Android"
Package name should be unique across the android system. A name like "com.my_name.helloandroid" can be used, were my_name is the name of the developer. Here, the name used is com.android.HelloAndroid.
Create Activity is the name of the default activity. Activity is similar to a screen/window in windows. 
Min SDK Version is the minimum version of sdk required for the app to run. With android sdk 2.2, this version is 8.
Click on the finish button, and the ADK pluggin will create the app for you.




Click on the Run button or Run -> Run from menu. This will start the android emulator (which will take some time depending on your system configuration), install the new app into the device and run the app. The output of the HelloAndroid app will  be




Now, from where did the comments "Hello World, HelloAndroid" come?
If you check the file strings.xml in ./res/values folder you'll get the answer. This was created by ADT pluggin that we used!!!



A complete description of the "HelloAndroid" app will be provided in the next few blog posts. Before that lets see what we have done to create the app:

  1. Create a new android project in eclipse from File -> New -> Android Project 
  2. Fill in the details for Project name, Application name, Package name, Create Activity and Min SDK Version in the New Android Project window
  3. Save the project and run
  4. Wait till the android emulator starts and the application is run

Eclipse setup for android

Download eclipse from ttp://www.eclipse.org/downloads and the ADT pluggin available for eclipse from http://dl.google.com/android/ADT-0.9.9.zip.
Now start eclipse and go to Help - Install New Software. This brings up the below screen.


Uncheck the option "Contact all update sites during install to find required software" to avoid unnecessary online updates. Now click the Add button and the Add Site window is opened. 


Click on the Archive button. Select the downloaded ADT zip file from the browser screen that is opened.

Select OK in the Add Site, and click "Finish" in the installation window. This completes installation of ADT. It is highly recommended that you use ADT as it reduces the effort required for android app development.

Now start eclipse and set the sdk path. For this, select Windows -> Preferences from the eclipse's menu. Select "Android" from the left side menu. Set the path to which the sdk was extarcted to in "SDK Location" and click ok. After this Restart eclipse.


The final part is creation of Android Virtual Device AVD. This is also a straight forward process which can be done directly from eclipse. Select Window -> Android SDK and AVD Manager from eclipse menu. Select the option "Virtual Device" from the left hand side menu and click "New" in the screen that opens. 



A new window is opened. Give a Name for the virtual device. Select Target as Android 2.2 - API Level 8. The SD card size can be given anything greater than 9MB. Leave the rest as it is. Click "Create AVD" button at the bottom to create the virtual device.


With this, eclipse is ready for Android apps development.

The steps to be done are:
  1. Download and install eclipse from http://www.eclipse.org/downloads/
  2. Download ADT pluggin from http://dl.google.com/android/ADT-0.9.9.zip and install in eclipse
  3. Set the android sdk path in Eclipse from Eclipse -> Window -> Preferences
  4. Create an Android Virtual Device from Eclipse -> Window -> Android SDK and AVD Manager


Android sdk setup

The earlier sdk bundle that was thre for 1.5 & 1.6 has been replaced with a simpler and easier "SDK Manager". The download is available at http://dl.google.com/android/android-sdk_r07-windows.zip. Extract the zip file to a folder, say - C:\Android\sdk. Now, go to the folder C:\Android\sdk and run the SDK Manager.exe. This will bring up the "Android SDK and AVD Manager". This will bring up the below window


Select the "Available Packages" option (third in the left hand side menu), and a list of available packages are shown. Select the ones that is required - Android sdk tools 7, SDK platform Android 2.2 are enough, but I would recommend Documentation for Android sdk API 8 and Samples for SDK API 8. After making the selections, click on the "Install selected" button in the bottom right corner.

This will download and install the selected components into C:\Android\sdk

To add the android sdk path to the windows PATH list, open the Windows Environment Variables window (Right click on My Computer, then System Properties -> Advanced -> Environment Variables. 



Click on the New button if the variable PATH does not exist. If it exists, click Edit. In the window that pops up, define variable PATH and value as the path to the tools folder of the android sdk - C:\Android\sdk\tools.


The last thing thats required is JDK. Download the latest jdk from  and install it. This completes the android sdk setup.


So, the steps for android sdk setup is:

  1. Download sdk manager from http://dl.google.com/android/android-sdk_r07-windows.zip
  2. Extract the zip file to a folder - C:\Android\sdk\
  3. Run sdk manager and download the sdk components. The adviced components are
    • Android sdk tools 7
    • SDK platform Android 2.2
    • Documentation for Android sdk, API 8
    • Samples for SDK API 8
  4. Add path to android sdk tools (C:\Android\sdk\tools) in windows PATH environment variable.
  5. Download and install the latest jdk. JDK is available for download from http://www.oracle.com/technetwork/java/javase/downloads/index.html.