page.title=Running Your App parent.title=Building Your First App parent.link=index.html trainingnavtop=true previous.title=Creating a Project previous.link=creating-project.html next.title=Building a Simple User Interface next.link=building-ui.html @jd:body
If you followed the previous lesson to create an Android project, it includes a default set of "Hello World" source files that allow you to run the app right away.
How you run your app depends on two things: whether you have a real Android-powered device and whether you’re using Eclipse. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Eclipse or the command line tools.
Before you run your app, you should be aware of a few directories and files in the Android project:
AndroidManifest.xml
src/
res/
drawable-hdpi/
layout/
values/
When you build and run the default Android project, the default {@link android.app.Activity}
class in the src/
directory starts and loads a layout file from the
layout/
directory, which includes a "Hello World" message. Not real exciting, but it's
important that you understand how to build and run your app before adding real functionality to
the app.
Whether you’re using Eclipse or the command line, you need to:
To run the app from Eclipse, open one of your project's files and click Run from the toolbar. Eclipse installs the app on your connected device and starts it.
Or to run your app from a command line:
ant debug
platform-tools/
directory is included in your
PATH
environment variable, then execute:
adb install bin/MyFirstApp-debug.apk
To start adding stuff to the app, continue to the next lesson.
Whether you’re using Eclipse or the command line, you need to first create an Android Virtual Device (AVD). An AVD is a device configuration for the Android emulator that allows you to model different device configurations.
Figure 1. The AVD Manager showing a few virtual devices.
To create an AVD:
<sdk>/tools/
and execute:
./android avd
To run the app from Eclipse, open one of your project's files and click Run from the toolbar. Eclipse installs the app on your AVD and starts it.
Or to run your app from the command line:
ant debug
platform-tools/
directory is included in your
PATH
environment
variable, then execute:
adb install bin/MyFirstApp-debug.apk
To start adding stuff to the app, continue to the next lesson.