How To Write Your First Google Android Application

android application designThe Android Market is taking off. In March, over 9,000 applications hit the Android market, doubling the amount added the previous month, impressing Android users everywhere. Given the huge amount of new Android phones coming out this year, it doesn’t seem like things are going to level off anytime soon.

Recently, Google announced that they are sending free Nexus One or Droid devices to developers with 3.5+ stars and 5,000+ downloads on their applications – making it that much more attractive to become a (good) Android developer and to come up with a good Android application design.


Want to know how to write Google Android apps? Android applications are written in Java – a relatively easy to learn, friendly language for new developers. Aside from the possibility of a free Nexus One and some money, you could actually contribute to the Android community. If you’ve got innovative ideas and the drive to see them spread, the Android market is for you! Let’s get you started on your very first Android application design.

Before we get to how to write Google Android apps – first, a bit of overview. Android apps (much like almost any mobile app) are developed on a computer – PC or Mac (generally) – and then compiled and sent to the device for testing. If you don’t have an Android device yet, there are emulators that simulate an Android device on your computer, meaning that you can still develop an Android game or application without owning one.

Step 1: Get Eclipse

For this tutorial, I’m going to use Eclipse, because frankly it’s the easiest and most hassle-free development tool for Android right now. If you’re a NetBeans programmer, be my guest; but I’ll use Eclipse today.

Download Eclipse IDE for Java Developers (PC or Mac, 92MB)

Note: This is a .zip file; when you unzip it you will be able to run it wherever you unpacked it – there is no installer. I’d recommend that you put this in “C:\Program Files\” unless you plan on making it a portable application on a USB drive or something.

Step 2: Download The Java JDK

If you don’t have it already, you need to download the Java JDK 6. If you currently have the JDK 5, you should be okay, but there’s really no reason not to update. Just install it by downloading and then running through the setup to get things going. I’d recommend that you just hit next–>next–>finish, rather than doing anything fancy. Once you get things working, you can mess around a bit.

Step 3: Download The Android SDK Tools

Next, you’ll need to get the Android SDK Tools straight from Google. Unpack and install this to a directory you’ll remember – you need to reference this in the next few steps.

Step 4: Configure Eclipse For Your Android

Start Eclipse, and head to ‘Help>Install New Software‘. Hit  “Add…” and for the name, type “Android” and set the link to “https://dl-ssl.google.com/android/eclipse/” (if this doesn’t work, try it with http:// instead of https://).Click “OK” and the following should appear.

android application design

Select both of the resulting packages, and hit next – this will download the Android ADT (Android Development Tools). Go ahead and start the download to obtain these two packages. Restart Eclipse (it should prompt you to on completion of the downloads). We’re almost ready to start coding.

Step 5: Configure The Android SDK

Navigate to the folder you downloaded/unpacked the Android SDK to. In there, you’ll find a file named “SDK Setup.exe.” Start that file – the following dialogue should appear.

android application development

Don’t feel obligated to download every single thing. Could it hurt? Not really. For me, however, I only really want to program for Android 2.1 and 2.01, so those are the only API packages I bothered to get (someday I may pay for my folly, but not today). Either way, get what you want (and you do need to pick one) and hit install. The SDK manager will install it for a little while – go grab a snack.

Step 6: Set Up Your Android Virtual Device (AVD)

Now that you’ve finished yet another painful download, click over to “virtual devices” (still in the SDK Manager). We’re going to create an Android device that will test run your programs for you! Hit “New” to create a new Android device, and put in the specifications that you want it to have. In the screenshot below, you’ll see the options I wanted (that closely mimic that of my Motorola Droid).

android application development

Click “Create AVD” to–well–create your AVD. Select your AVD from the list, and hit “Start” to make sure that you do indeed have a working emulation of an Android phone. After a pretty lengthy start-up wait, it should look something like this.

android application development

Fool around with it and explore for a bit if you want, then close it up so we can get back to work.

Step 7: Configure Eclipse Again

Remember that Android SDK we got earlier? We didn’t do anything with it. Now, it’s time to tell Eclipse where it is so Eclipse can use it as a resource. To do this, open Eclipse and navigate to Window>Preferences (or on Mac, Eclipse>Preferences) and select the Android tab. As shown below, browse to the location of your Android SDK and hit “Apply“.

android application development

Everything check out so far? Hit “OK” to save everything and let’s go program.

Step 8: Create A New Project

It’s finally time to code some. Navigate to ‘File>New>Other…>Android>Android Project‘, and input a project name, as well as some other details. If you want, copy from my screenshot below. Some of the fields need explaining that simply doesn’t belong here, so if you want to know more specifically, please let me know and maybe I’ll write an article about it.

android application development

Hit “Finish” and the project will be created.

Step 9: Input Your Code

In the tree on the left, navigate to the “src” folder and expand everything. Go to the file with the name of your “Activity” (created in step 8, mine was HelloWorld) and double click it to see the contents. Presently, your code has all of the content in black (with some minor modifications depending on your settings). To make a working “Hello world” program, you need to add the text that is in bold red. Note that there are two bold red “blocks” of code, and you need to add both to make things work.

//==========Start Code============

package com.android.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

//==========End Code============

I would love to explain all of the code in this Android application design, but that’s not exactly the point of this tutorial; the point is to get your feet off the ground. I know some/most of this is confusing; but it’s just how things are wired.

Step 10: Run Your Program

Above your code, you’ll see a little green “Play” button (or navigate to ‘Run>Run‘). Click it.When a popup box asks you how to run the application, you’re going to tell it to run as an “Android Application”. It will prompt you to save changes; hit yes.

Now you get to wait an eternity while your virtual device boots up. I’d recommend that you leave it open for the duration of your programming sprees, otherwise you’re going to spend more time watching the Android logo spin than you will watching your program freeze up. Just saying. Efficiency.

After everything’s done loading, your application should upload and start automatically. Which means that right after you “unlock” the device, you’ll be greeted with your first Android program.I only captured the top half of the screen because the rest of it is black.

android application design

That’s it, congratulations! The task can be a bit daunting at first; and definitely confusing, but if you stick with it you won’t be disappointed. If you step back and think about it, we only did a few really major things, the rest was just the process of connecting the pieces to make everything work.

Do you want to become an Android developer? Have you ever written an Android app, and if so, what did it do? As always I love getting feedback in the comments section. As someone who answered yes to the first question, I’m in the process of learning to adequately code for my Android device, so do you have any websites or pointers that would help me or a fellow Android newbie out?


MakeUseOf Recommends

More articles about:

36 Comments

Paul Bozzay

Former MakeUseOf author and technology enthusiast.

The comments were closed because the article is more than 180 days old.

If you have any questions related to stuff mentioned in the article or need help with any computer issue, just ask it on MakeUseOf Answers.

Hide 36 Comments

  • Steven Hope April 16, 2010
    0 likes

    Fantastic article! I was following using OSX but still managed it. Another example of why I love makeuseof.com. (My Hello World app http://twitpic.com/1g47pu)

    | Like
    • Steven Hope April 16, 2010
      0 likes

      huh…oops. remove the ) from the url

      | Like
    • pbozzay April 19, 2010
      0 likes

      Thank you! Always great to hear someone found something useful. Love the pic ;)

      | Like
  • Steven Hope April 17, 2010
    0 likes

    Fantastic article! I was following using OSX but still managed it. Another example of why I love makeuseof.com. (My Hello World app http://twitpic.com/1g47pu)

    | Like
  • Mark O'Neill April 17, 2010
    0 likes

    As an Android owner, I can personally attest that the Android Market is completely full of junk. Yes, there are the good apps too but they are hard to find because they are drowned out by all the crap. Google should have some kind of review procedure in place, much like Apple does, to remove all the crap clogging up the system.

    | Like
    • Chris June 4, 2010
      0 likes

      Which would completely miss the point of Android being Free, and negate any advantages over the iPhone.

      | Like
  • Alex April 17, 2010
    0 likes

    Anyone else getting errors when trying to connect to the software site via eclipse?? removing the ‘s’ doesn’t make a difference.

    | Like
    • Vinod April 18, 2010
      0 likes

      I’m facing the same trouble, can anyone help?

      | Like
    • Scott April 18, 2010
      0 likes

      In order to do this you have to go to the “settings” on the left side and put a check mark in the “Force https//…” box.
      Then it will be fine

      | Like
      • Alex April 18, 2010
        0 likes

        sorry, i don’t see “settings” anywhere in eclipse

        | Like
        • pbozzay April 19, 2010
          0 likes

          You most likely have a firewall blocking the download–you’ve got two options.

          You can configure Eclipse to use your web browser’s proxy settings, or download the package manually. Because the proxy settings option is a bit more difficult, here’s the second option:

          http://developer.android.com/sdk/eclipse-adt.html#troubleshooting

          See the part where it gives you the ADT package install .zip file, and follow steps 1-6 below that. Let me know if it works!

          | Like
  • Scott April 18, 2010
    0 likes

    In order to do this you have to go to the “settings” on the left side and put a check mark in the “Force https//…” box.
    Then it will be fine

    | Like
  • Nevadascott April 18, 2010
    0 likes

    Thanks so much! this is a great way to get a start! Would like to see more!!!

    | Like
    • pbozzay April 19, 2010
      0 likes

      Thanks for the feedback; anything in particular you want to see?

      | Like
  • PaulB2 April 19, 2010
    0 likes

    You most likely have a firewall blocking the download–you’ve got two options.

    You can configure Eclipse to use your web browser’s proxy settings, or download the package manually. Because the proxy settings option is a bit more difficult, here’s the second option:

    http://developer.android.com/s

    See the part where it gives you the ADT package install .zip file, and follow steps 1-6 below that. Let me know if it works!

    | Like
  • kumarann April 19, 2010
    0 likes

    The step by step procedure has been explained in the greater way as started with welcome message “Hello Android” like Java programming introduction.
    the wonderful option in android development is that everything will be available in open source. No need to pay for anything.
    I want Android to be the number one in the World in mobile application in the nearest future.

    | Like
  • kumarann April 19, 2010
    0 likes

    The step by step procedure has been explained in the greater way as started with welcome message “Hello Android” like Java programming introduction.
    the wonderful option in android development is that everything will be available in open source. No need to pay for anything.
    I want Android to be the number one in the World in mobile application in the nearest future.

    | Like
  • Alex April 20, 2010
    0 likes

    Thank you for the help, unfortunately i still havent gotten it working. Eclipse claims there is no repository, and occasionally it will simply say “there are no categorized items.”

    | Like
    • pbozzay April 22, 2010
      0 likes

      I’ve looked everywhere and can’t find a solution for you. Your best bet might be to restart the process or try from another computer. Are you doing this on windows or mac?

      You have to make sure you do the steps in order because some of them depend on each other to work.

      | Like
    • eegor April 24, 2010
      0 likes

      Hey Alex, you should be able to download the plugin seperately from here: http://developer.android.com/sdk/eclipse-adt.html#troubleshooting. Hope that helps.

      There are also some good ‘getting started’ tutorials at http://androidforbeginners.blogspot.com.

      | Like
  • Jeremy April 21, 2010
    0 likes

    Hey Paul, thanks for a great article, to at least to give me starting point but my question is- how do you write a app? Ive got some great ideas (well…in my mind atleast.) but I dont know how to write code for them. Is there a future article on this?

    | Like
    • pbozzay April 21, 2010
      0 likes

      You need to know Java Programming [at least some of it] to write apps using the method in this article. Plus, there are some differences in the framework and how things need to be written for an Android device as opposed to, say, a PC. There’s books out there covering what you need to know–but I’d be happy to give it a go in an article if you want.

      Anything specific you want to see? I’d be happy to write another [related] article if there’s interest.

      | Like
  • PaulB2 April 21, 2010
    0 likes

    You need to know Java Programming [at least some of it] to write apps using the method in this article. Plus, there are some differences in the framework and how things need to be written for an Android device as opposed to, say, a PC. There’s books out there covering what you need to know–but I’d be happy to give it a go in an article if you want.

    Anything specific you want to see? I’d be happy to write another [related] article if there’s interest.

    | Like
  • PaulB2 April 22, 2010
    0 likes

    I’ve looked everywhere and can’t find a solution for you. Your best bet might be to restart the process or try from another computer. Are you doing this on windows or mac?

    You have to make sure you do the steps in order because some of them depend on each other to work.

    | Like
  • Gary April 24, 2010
    0 likes

    I liked this article VERY MUCH. It got me all fired up about learning to program in Android. However, I wanted to save the article for future reference and I did not see a way to do this . Help!!

    | Like
    • Aibek April 24, 2010
      0 likes

      The ShareThis bookmarklet at the end of the blog lets you save the
      article to pretty much any social bookmarking website (del.icio.us) or
      email it to yourself.

      Aibek

      | Like
      • Garymol April 27, 2010
        0 likes

        Thanks a lot!!
        I was able to look for the bookmark you indicated and sent myself the article.

        | Like
  • Aibek April 24, 2010
    0 likes

    The ShareThis bookmarklet at the end of the blog lets you save the
    article to pretty much any social bookmarking website (del.icio.us) or
    email it to yourself.

    Aibek

    | Like
  • Garymol April 28, 2010
    0 likes

    Thanks a lot!!
    I was able to look for the bookmark you indicated and sent myself the article.

    | Like
  • hari May 6, 2010
    0 likes

    Hey Paul, that was very useful article. I bought htc hero months back thinking that i would have some fun programming, but never got myself to kickstart it..Now that i have something to start from..lets see how it goes..

    | Like
    • Aibek May 6, 2010
      0 likes

      Hey Hari

      Let us know how it goes :-)

      Aibek

      | Like
  • Aibek May 6, 2010
    0 likes

    Hey Hari

    Let us know how it goes :-)

    Aibek

    | Like
  • Goggletron June 7, 2010
    0 likes

    Thanks, this helped alot.

    | Like
  • Sweetvani4u June 16, 2010
    0 likes

    hello every one!!!!
    i have one problem, in android project if it have more than 1 activity than how to write project,
    in one project we write all activity?, or write different project for every different activity?

    | Like
  • Sweetvani4u June 16, 2010
    0 likes

    hello every one!!!!
    i have one problem, in android project if it have more than 1 activity than how to write project,
    in one project we write all activity?, or write different project for every different activity?

    | Like
  • Marcel July 5, 2010
    0 likes

    Works great! Only thing to emphasize, the emulator really, really, really takes a damn long time to start. First you see “A d r o i d”, then after minutes the logo and minutes later the android desktop. So be patient trying the emulator out. Once started, keep it running otherwise you’ll need to wait and wait and wait again…

    | Like