In the previous lesson, you created an Android project that displays "Hello World." You can now run the app on a real device or on an emulator. If you don't have a real device available, skip to Run on an Emulator.
Run on a Real Device
Set up your device as follows:
Connect your device to your development machine with a USB cable. If you're developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the OEM USB Drivers document.
Enable USB debugging on your device by going to
Settings>Developer options
.
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.
Run the app from Android Studio as follows:
In Android Studio, select your project and click Run from the toolbar.
In the Select Deployment Target window, select your device, and click OK.
Android Studio installs the app on your connected device and starts it.
Run on an Emulator
Before you run your app on an emulator, you need to create an Android Virtual Device (AVD) definition. An AVD definition defines the characteristics of an Android phone, tablet, Android Wear, or Android TV device that you want to simulate in the Android Emulator.
Create an AVD Definition as follows:
Launch the Android Virtual Device Manager by selecting Tools>Android>AVD Manager, or by clicking the AVD Manager icon in the toolbar.
In the Your Virtual Devices screen, click Create Virtual Device.
In the Select Hardware screen, select a phone device, such as Nexus 6, and then click Next.
In the System Image screen, choose the desired system image for the AVD and click Next.
If you don't have a particular system image installed, you can get it by clicking the download link.
Verify the configuration settings (for your first AVD, leave all the settings as they are), and then click Finish.
For more information about using AVDs, see Create and Manage Virtual Devices.
Run the app from Android Studio as follows:
In Android Studio, select your project and click Run from the toolbar.
In the Select Deployment Target window, select your emulator and click OK.
It can take a few minutes for the emulator to start. You may have to unlock the screen. When you do, My First App appears on the emulator screen.
That's how you build and run your Android app on the emulator! To start developing, continue to the next lesson.