Wednesday, April 27, 2011

Creating Your First Android App

Today I am going to walk you through installing and setting up the Android SDK so you can create android applications. Android runs on Java, so if you don’t know Java, please step away now. If you want to try it anyway, keep following along. We first need to install JDK, the Java Development Kit. We will be installing JDK 5 which is the latest version as of writing this.

We will be using Windows to install these on, I will be using x86, you can probably follow along on the other OS’s Java supports, but if your semi new to this, you might want to open Windows in a VM to follow along. Hopefully by now your installing or at least downloading the JDK. I downloaded jdk-6u24-windows-i586.exe. I even created a small YouTube video for the install, which is pretty much point and click next..

We haven’t really discussed what kind of app we will be making. We will be writing a simple app of course, nothing too fancy. We will not be integrating controls at this time such as Buttons or Labels, that will follow in the next tutorial where we will be creating a simple calculator. For now, we need to continue with our setup and install our IDE, we will be using Eclipse. The Eclipse IDE is something I have been using for quite some time, since I went through the core. No, not the corps., the core. The core is something familiar to programmers, it is the basis/structure from which most coders who have gone to school learn the basics and fundamentals for programming.

Once Eclipse installs it has options to download and install the Android SDK. I will be downloading and installing helios SR2. There is an option to download it via torrent, which id the option I am going to use. Once it is done downloading just extract the eclipse folder to a place of your choosing and start the IDE.

Posted Image

On the left is the default package for the Eclipse IDE we downlaoded, click the eclipse.exe to get it going. It will ask you to select a workspace, just hit ok or whatever it asks, unless you want to specify a different location. Once it loads go into the Help menu at the top and select Install New Software. A new windows will pop up and enter the URL: into it and press enter. Select them all and click Next at the bottom to start installing. It may take a while depending on your PC’s speed and internet connection, just be patient. Accept the License Agreements and click Finish. You will have to restart Eclipse.

Now, go to Window then select Preferences and select Android from the left menu and then select the Android version, we will be using 1.5 for this project, press the Apply button.

Posted Image

Now open the AVD manager.

Posted Image

Select start to start the Android emulator. It may take a while to load, it looks something like below.

Posted Image

The images presented in this tutorial are for the 1.5 AVD, however here is a video that shows how to load the AVD, but it is using 2.3, it still shows you how to load the AVD from within Eclipse.

For now, we can just load a new Android project and do a simple Hello World. Select File then New Project and select the Android project.

Posted Image

Now setup the projects preferences.

Posted Image

Instead of typing 1.5 for the Minimum SDK version type 3 instead. My bad, when compiling the project you can get an error like this: [2011-03-16 12:00:05 - HelloWorld] Manifest attribute ‘minSdkVersion’ is set to ’1.5′. Integer is expected. Then you will know exactly what I did wrong previously, typing 1.5 instead of 3. You should be able to open the AndroidManifest.xml file and edit the 1.5 and change it to 3.

Posted Image

Now, we should be good to go and place a simple Hello World in the source.

package com.lerie.helloworld;
import android.os.Bundle;
 public class HelloWorld extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        System.out.println("Hello World!");

You can now open the AVD manager, launch the Android and run the demo. (the green play button in the toolbar). Enjoy.

Posted Image

No comments:

Post a Comment