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 immediately run the app.
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
One of the most important elements your manifest should include is the {@code <uses-sdk>} element. This declares your app's compatibility with different Android versions using the {@code android:minSdkVersion} and {@code android:targetSdkVersion} attributes. For your first app, it should look like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> ... </manifest>
You should always set the {@code android:targetSdkVersion} as high as possible and test your app on the corresponding platform version. For more information, read Supporting Different Platform Versions.
src/
res/
drawable-hdpi/
layout/
values/
When you build and run the default Android app, the default {@link android.app.Activity} class starts and loads a layout file that says "Hello World." The result is nothing exciting, but it's important that you understand how to run your app before you start developing.
If you have a real Android-powered device, here's how you can install and run your app:
Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
To run the app from Eclipse:
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
That's how you build and run your Android app on a device! To start developing, continue to the next lesson.
Whether you're using Eclipse or the command line, to run your app on the emulator 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 devices.
To create an AVD:
<sdk>/tools/
and execute:
android avd
To run the app from Eclipse:
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
That's how you build and run your Android app on the emulator! To start developing, continue to the next lesson.