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