1 page.title=Running Your App 2 parent.title=Building Your First App 3 parent.link=index.html 4 5 trainingnavtop=true 6 7 page.tags=emulator 8 helpoutsWidget=true 9 10 @jd:body 11 12 13 <!-- This is the training bar --> 14 <div id="tb-wrapper"> 15 <div id="tb"> 16 17 <h2>This lesson teaches you to</h2> 18 19 <ol> 20 <li><a href="#RealDevice">Run on a Real Device</a></li> 21 <li><a href="#Emulator">Run on the Emulator</a></li> 22 </ol> 23 24 <h2>You should also read</h2> 25 26 <ul> 27 <li><a href="{@docRoot}tools/device.html">Using Hardware Devices</a></li> 28 <li><a href="{@docRoot}tools/devices/managing-avds.html">Managing AVDs with AVD Manager</a></li> 29 <li><a href="{@docRoot}tools/projects/index.html">Managing Projects</a></li> 30 </ul> 31 32 33 </div> 34 </div> 35 36 37 <p>If you followed the <a href="creating-project.html">previous lesson</a> to create an 38 Android project, it includes a default set of "Hello World" source files that allow you to 39 immediately run the app.</p> 40 41 <p>How you run your app depends on two things: whether you have a real device running Android and 42 whether you're using Android Studio. This lesson shows you how to install and run your app on a 43 real device and on the Android emulator, and in both cases with either Android Studio or the command 44 line tools.</p> 45 46 <h2 id="RealDevice">Run on a Real Device</h2> 47 48 <p>If you have a device running Android, here's how to install and run your app.</p> 49 50 <h3>Set up your device</h3> 51 52 <ol> 53 <li>Plug in your device to your development machine with a USB cable. 54 If you're developing on Windows, you might need to install the appropriate USB driver for your 55 device. For help installing drivers, see the <a href="{@docRoot}tools/extras/oem-usb.html">OEM 56 USB Drivers</a> document.</li> 57 <li>Enable <strong>USB debugging</strong> on your device. On Android 4.0 and newer, go to 58 <strong>Settings > Developer options</strong>. 59 <p class="note"><strong>Note:</strong> On Android 4.2 and newer, <strong>Developer 60 options</strong> is hidden by default. To make it available, go 61 to <strong>Settings > About phone</strong> and tap <strong>Build number</strong> 62 seven times. Return to the previous screen to find <strong>Developer options</strong>.</p> 63 </li> 64 </ol> 65 66 <h3>Run the app from Android Studio</h3> 67 <ol> 68 <li>Select one of your project's files and click 69 <strong>Run</strong> <img 70 src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> 71 from the toolbar.</li> 72 <li>In the <strong>Choose Device</strong> window that appears, select the 73 <strong>Choose a running device</strong> radio button, select your device, and click <strong>OK 74 </strong>.</li> 75 </ol> 76 <p>Android Studio installs the app on your connected device and starts it.</p> 77 78 79 <h2 id="Emulator">Run on the Emulator</h2> 80 81 <p>Whether you're using Android Studio or the command line, to run your app on the emulator you need 82 to first create an <a href="{@docRoot}tools/devices/index.html">Android Virtual Device</a> (AVD). An 83 AVD is a device configuration for the Android emulator that allows you to model a specific 84 device.</p> 85 86 87 <h3>Create an AVD</h3> 88 <ol> 89 <li>Launch the Android Virtual Device Manager: 90 <ul> 91 <li>In Android Studio, select <strong>Tools > Android > AVD Manager</strong>, or click 92 the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png" 93 style="vertical-align:bottom;margin:0;height:19px"> in the toolbar. The 94 <em>AVD Manager</em> screen appears.</li> 95 <li>Or, from the command line, change directories to 96 <code>sdk/</code> and execute: 97 <pre class="no-pretty-print">tools/android avd</pre> 98 <p class="note"><strong>Note:</strong> The AVD Manager that appears 99 when launched from the command line is different from the version in 100 Android Studio, so the following instructions may not all apply.</p> 101 </li> 102 </ul> 103 104 </li> 105 <li>On the AVD Manager main screen, click <strong>Create Virtual Device</strong>.</li> 106 <li>In the Select Hardware window, select a device configuration, such as Nexus 6, 107 then click <strong>Next</strong>. 108 </li> 109 <li>Select the desired system version for the AVD and click <strong>Next</strong>. 110 </li> 111 <li>Verify the configuration settings, then click <strong>Finish</strong>. 112 </li> 113 </ol> 114 115 <p>For more information about using AVDs, see 116 <a href="{@docRoot}tools/devices/managing-avds.html">Managing AVDs with AVD Manager</a>.</p> 117 118 <h3>Run the app from Android Studio</h3> 119 <ol> 120 <li>In <strong>Android Studio</strong>, select your project and click <strong>Run</strong> 121 <img src="{@docRoot}images/tools/as-run.png" style="vertical-align:baseline;margin:0; max-height:1em" /> from the toolbar.</li> 122 <li>In the <strong>Choose Device</strong> window, click the <strong>Launch emulator</strong> radio 123 button.</li> 124 <li>From the <strong>Android virtual device</strong> pull-down menu, select the emulator 125 you created, and click <strong>OK</strong>.</li> 126 </ol> 127 <p>It can take a few minutes for the emulator to load itself. You may have to unlock the screen. 128 When you do, <em>My First App</em> appears on the emulator screen.</p> 129 130 131 <p>That's how you build and run your Android app on the emulator! 132 To start developing, continue to the <a href="building-ui.html">next 133 lesson</a>.</p> 134 135 136