Main Tutorials

Android hello world example

In this tutorial, we show you how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD). The Eclipse ADT plugin provided easy Android project creation and management, components drag and drop, auto-complete and many useful features to speed up your Android development cycles.

Summary steps to develop an Android application :

  1. Install Android SDK
  2. Install ADT Eclipse plugin
  3. Create an Android Virtual Device (AVD)
  4. Create Android Project with Eclipse (Wizard)
  5. Code it…
  6. Start it in Android Virtual Device (AVD)

Tools used in this tutorial :

  1. JDK 1.6
  2. Eclipse IDE 3.7 , Indigo
  3. Android SDK

1. Install Android SDK

Visit this Android SDK page, choose which platform and install it.

In Android SDK installed folder, run “Android SDK manager”, choose what Android version you want to develop.

android sdk manager

2. Install ADT Eclipse plugin

To integrate Android SDK with Eclipse IDE, you need to install Eclipse ADT plugin. Refer to this official guide – “Installing the ADT Plugin“.

In Eclipse IDE, select “Help” -> Install New Software…”, and put below URL :


https://dl-ssl.google.com/android/eclipse/
android ADT plugin
Note
In my case, above ADT plugin is taking years to download, no idea why. If you are facing the similar problem, just download and install the ADT plugin manually, refer to this ADT plugin troubleshooting guide.

3. Create an Android Virtual Device (AVD)

In Eclipse, you can access the “Android Virtual Device (AVD)” in Eclipse toolbar. Click “new” to create a AVD.

android avd manager

Later, Eclipse will deploy the application into this AVD.

4. Create Android Project

In Eclipse, select “File -> New -> Project….”, “Android Project”, and input your application detail. Eclipse will create all the necessary Android project files and configuration.

Eclipse new android project wizard
folder structure

5. Hello World

Locate the generated activity file, and modify a bit to output a string “Hello World”.

File : HelloWorldActivity.java


package com.mkyong.android;

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

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

6. Demo

Run it as “Android Application“, see output.

hello world output

Press “Home” button (on right hand side), and you will noticed that “HelloWorld” application is deployed successfully on the Android virtual device.

android deployed
Note
This tutorial is more to example driven, not much explanation. For detail and complete explanation, please refer to the official Android developer hello world tutorial.
Firewall…
In my computer, the COMODO firewall is installed and blocked the deploying process, caused the connection between Eclipse ADT and AVD is blocked and failed to deploy. Just make sure your firewall is configured properly, or just turn it off for Android development 🙂
Debug Android application on real device
Sometime, “Android Virtual Device” is not enough to test some real phone functionalities, like led light, sensor and etc. Then you should refer to this how to debug Android application on real device.

Download Source Code

Download it – Android-HelloWorld.zip (15 KB)

References

  1. Android Developers

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
64 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Shiv Ganesh
6 years ago

I was just venturing through your post and found that these are a bit old and outdated. Are you having any plans to update them so that we can use Android Studio and get started. I have really liked your site from a long time and thought of suggesting.

Sreedhar Siliveri
12 years ago

Hi Yong
Great start about Android .. Please publish more tutorials in depth. I wanna start my safe journey into “smart” Android world.

Thanks
Sreedhar

Naveen
11 years ago
Reply to  mkyong

HI Mkyng,
This is very good tutorial to start. My application failed with below console error. Can you
advise where I goes wrong:
[2012-12-28 07:47:37 – HelloWorld] Launching a new emulator with Virtual Device ‘MyFirstAndriod’
[2012-12-28 07:47:47 – Emulator] Failed to create Context 0x3005
[2012-12-28 07:47:47 – Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB
[2012-12-28 07:47:47 – Emulator] could not get wglGetExtensionsStringARB

Paul Brown
1 year ago

i played almost all of these games. except the ones with low graphic art like f-zero, mario kart, castlevania, metroid etc. contra had low graphic but very enjoyable with co-op. earthbound, ff should be top5. idk how many times i’ve replayed crono trigger and earthworm jim. others mostly 75%.
<a href=”https://thefucksites.com/”>Paul Brown</a>

Trey
6 years ago

It is not Java it is different.

Philip Jeffrey Trowe
9 years ago

Check out my blog. It provides a video to show you how to create your first Android Hello World app.

http://androidprogrammeringcorner.blogspot.com/2015/02/pak-longs-programming-corner-for.html

Best regards,

Philip

Prem Pratick Kumar
9 years ago

Please post for in this sections. Its really helpful.

Cashlele
9 years ago

Hey mkyong, I m new in android application development.So this tutorial really helped to get all basic things .Thanks man..!!!
http://www.cashlele.com

likhith
9 years ago

hi Mkyong…. I am new to android …. ia have serious problem when i creatyed my first application… the virtual device which i created fail to load and emulator launch is failed for simple Hello world applciation… so can u support to rectify the problem

mukesh jat
9 years ago

not sufficient info 🙁
http://www.india.dj

Ian Kim
9 years ago

thanks sir

Nithin kumar
10 years ago

i am not able to install the adt packages to eclipse juno in windows 7

Dinesh
10 years ago

Thank you !! The tutorial was very simple for beginners..Thanks again..

Anuvab Ghosh
10 years ago

Thank u Sir…This is helpful to setup and to complete the first Apps in Android.

mtive
10 years ago

sir this is very informative i want to learn that how to earn with android development plz guide
i found a very use full learn4do . com

SATHVIK
10 years ago

Need temperature converting program

plss need it urjent!!!

Thanks in advance

FROM ALIET

DHARANI
10 years ago

thanks :):)

matao
10 years ago

android

Sunny
10 years ago

Great start with android.waiting for more on Android tuts from you sir.

regards,
Sunny

Sunny
10 years ago

Great start with android.waiting for more on Android tuts from you sir.
http://websnube.com/

regards,
Sunny

Nitin
10 years ago

Hi,

I am completely new in this and I followed all the above steps but for me under new project –> Android, ‘android project’ is not present. Could you elaborate a little more on each step. How to add AVT (MyAndroid). I have eclipse indigo release 2 and Android 4.2.2. Help me in executing the hello world atleast.

Arun
10 years ago

I’ve built a very small game app that has no more than two activities and so two java classes. But the apk that I get out of it is abt 800KB. But I see apps on store that are even lesser than 400 KB. And those apps are definitely no of just two java classes. For example a MP3 cutter is of 400KB. Even Opera browser is of just 804KBs. What do they do to reduce the size of the apk? Do I have any unwanted files/images in my eclipse project that have been created by default?

pavan
10 years ago

very nice tutorial you can also check this one
http://pavanhd.blogspot.in/2012/09/android-hello-world-example.html

Meghna
10 years ago

Thanks for the clean explanation.. This website http://www.compiletimeerror.com/2012/12/creating-first-androidapplication-in.html also addresses something similar.. Have a look, may help..

anu
10 years ago

good tutorial

kanimozhi
10 years ago

thank

Ashish
10 years ago

Hello Friends

If u want run emulator using command prompt then go to c:\program files\android\android_sdk\platform_tools

and keep your apk on platform tools

and issue command on cmd : cd c:\prorgram files\android\android_sdk\platform_tools

then run adb install filename.apk

if u want run directly on your mobile then issue command:

adb -d install filename.apk

godel
10 years ago

hai mkyong…..

i’m using eclipse juno
it’s AVD emulator not working. why?

it’s error code is
PANIC : not open android
(my avd create with name android)

please help me
contact me by email
thanks

dev
10 years ago
Reply to  godel
Sanal San
11 years ago

Hai MkYong,
I am doing Android applications.Thanks for your demo work.Please publish more tutorials.

Thanking you.

With regards,
Sanal

http://www.guidehorse.com/
11 years ago

Howdy just wanted to give you a quick heads up. The
text in your article seem to be running off the screen in Safari.
I’m not sure if this is a formatting issue or something to do with web browser compatibility but I thought I’d post to let you know.
The design and style look great though! Hope you get the issue solved soon.
Many thanks