summaryrefslogtreecommitdiff
path: root/docs/html/training/basics/firstapp/running-app.jd
blob: 085849fe34d60c45d4f535646930ab919df85dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
page.title=Running Your App
parent.title=Building Your First App
parent.link=index.html

trainingnavtop=true
page.tags=emulator

@jd:body


<!-- This is the training bar -->
<div id="tb-wrapper">
<div id="tb">

<h2>This lesson teaches you to</h2>

<ol>
  <li><a href="#RealDevice">Run on a Real Device</a></li>
  <li><a href="#Emulator">Run on an Emulator</a></li>
</ol>

<h2>You should also read</h2>

<ul>
  <li><a href="{@docRoot}tools/device.html">Using Hardware Devices</a></li>
  <li><a href="{@docRoot}tools/devices/managing-avds.html">Managing AVDs with AVD Manager</a></li>
</ul>


</div>
</div>


<p>In the <a href="creating-project.html">previous lesson</a>, 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
<a href="#Emulator">Run on an Emulator</a>.</p>


<h2 id="RealDevice">Run on a Real Device</h2>

<p>Set up your device as follows:</p>

<ol>
  <li>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 <a href="{@docRoot}studio/run/oem-usb.html">OEM
    USB Drivers</a> document.</li>
  <li>Enable <strong>USB debugging</strong> on your device by going to
    <strong>Settings > Developer options</strong>.
        <p class="note"><strong>Note:</strong> On Android 4.2 and newer, <strong>Developer
        options</strong> is hidden by default. To make it available, go
        to <strong>Settings > About phone</strong> and tap <strong>Build number</strong>
        seven times. Return to the previous screen to find <strong>Developer options</strong>.</p>
  </li>
</ol>

<p>Run the app from Android Studio as follows:</p>

<ol>
  <li>In Android Studio, select your project and click
    <strong>Run</strong> <img src="{@docRoot}images/tools/as-run.png"
    style="vertical-align:baseline;margin:0; max-height:1em" />
    from the toolbar.</li>
  <li>In the <strong>Select Deployment Target</strong> window,
    select your device, and click <strong>OK</strong>.</li>
</ol>
<p>Android Studio installs the app on your connected device and starts it.</p>


<h2 id="Emulator">Run on an Emulator</h2>

<p>Before you run your app on an emulator, you need to create an
  <a href="{@docRoot}tools/devices/index.html">Android Virtual Device</a> (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.</p>

<p>Create an AVD Definition as follows:</p>
<ol>
  <li>Launch the Android Virtual Device Manager by selecting
    <strong>Tools &gt; Android &gt; AVD Manager</strong>, or by clicking
    the AVD Manager icon <img src="{@docRoot}images/tools/avd-manager-studio.png"
    style="vertical-align:bottom;margin:0;height:19px"> in the toolbar.</li>
  <li>In the <b>Your Virtual Devices</b> screen, click <strong>Create Virtual Device</strong>.</li>
  <li>In the <b>Select Hardware</b> screen, select a phone device, such as Nexus 6,
    and then click <strong>Next</strong>.
  </li>
  <li>In the <b>System Image</b> screen, choose the desired system image for the AVD and
    click <strong>Next</strong>.
    <p>If you don't have a particular system image installed,
    you can get it by clicking the <b>download</b> link.</p>
  </li>
  <li>Verify the configuration settings (for your first AVD, leave all the
    settings as they are), and then click <strong>Finish</strong>.
  </li>
</ol>

<p>For more information about using AVDs, see
<a href="{@docRoot}studio/run/managing-avds.html">Create and Manage Virtual Devices</a>.</p>

<p>Run the app from Android Studio as follows:</p>
<ol>
  <li>In <strong>Android Studio</strong>, select your project and click
    <strong>Run</strong> <img src="{@docRoot}images/tools/as-run.png"
    style="vertical-align:baseline;margin:0; max-height:1em" />
    from the toolbar.</li>
  <li>In the <strong>Select Deployment Target</strong> window,
    select your emulator and click <strong>OK</strong>.</li>
</ol>
<p>It can take a few minutes for the emulator to start. You may have to unlock the screen.
When you do, <em>My First App</em> appears on the emulator screen.</p>


<p>That's how you build and run your Android app on the emulator!
To start developing, continue to the <a href="building-ui.html">next
lesson</a>.</p>