summaryrefslogtreecommitdiffstats
path: root/docs/html/tools/device.jd
blob: 5d8d3842008a1abd99c2a86ab7d87e73b8f53d09 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
page.title=Using Hardware Devices
@jd:body

<div id="qv-wrapper">
<div id="qv">
  <h2>In this document</h2>
  <ol>
    <li><a href="#device-developer-options">Enabling On-device Developer Options</a></li>
    <li><a href="#setting-up">Setting up a Device for Development</a>
      <ol>
        <li><a href="#VendorIds">USB Vendor IDs</a></li>
      </ol>
    </li>
  </ol>
  <h2>See also</h2>
  <ol>
    <li><a href="{@docRoot}sdk/win-usb.html">Google USB Driver</a></li>
    <li><a href="{@docRoot}tools/extras/oem-usb.html">OEM USB Drivers</a></li>
  </ol>
</div>
</div>

<p>When building a mobile application, it's important that you always test your application on a
real device before releasing it to users. This page describes how to set up your development
environment and Android-powered device for testing and debugging on the device.</p>

<p>You can use any Android-powered device as an environment for running,
debugging, and testing your applications. The tools included in the SDK make it easy to install and
run your application on the device each time you compile. You can install your application on the
device directly from Android Studio or from the command line with ADB. If
you don't yet have a device, check with the service providers in your area to determine which
Android-powered devices are available.</p>

<p>If you want a SIM-unlocked phone, then you might consider a Nexus phone. To purchase a
Nexus phone, visit the <a href="https://play.google.com/store/devices">Google Play</a> store.</p>

<p class="note"><strong>Note:</strong> When developing on a device, keep in mind that you should
still use the <a
href="{@docRoot}tools/devices/emulator.html">Android emulator</a> to test your
application
on configurations that are not equivalent to those of your real device. Although the emulator
does not allow you to test every device feature (such as the accelerometer), it does
allow you to verify that your application functions properly on different versions of the Android
platform, in different screen sizes and orientations, and more.</p>


<h2 id="developer-device-options" style="margin-bottom: 0px;">Enabling On-device Developer Options</h2>

<img src="/images/tools/dev-options-inmilk.png" alt="" style="float:right;margin-left:30px">

<p>Android-powered devices have a host of developer options that you can
access on the phone, which let you:</p>
<ul>
  <li>Enable debugging over USB.</li>
  <li>Quickly capture bug reports onto the device.</li>
  <li>Show CPU usage on screen.</li>
  <li>Draw debugging information on screen such as layout bounds,
    updates on GPU views and hardware layers, and other information.</li>
  <li>Plus many more options to simulate app stresses or enable debugging options.</li>
</ul>
<p>To access these settings, open the <em>Developer options</em> in the
system Settings. On Android 4.2 and higher, the Developer options screen is
hidden by default. To make it visible, go to
<b>Settings &gt; About phone</b> and tap <b>Build number</b> seven times. Return to the previous
screen to find Developer options at the bottom.</p>




<h2 id="setting-up">Setting up a Device for Development</h2>

<p>With an Android-powered device, you can develop and debug your Android applications just as you
would on the emulator. Before you can start, there are just a few things to do:</p>

<ol>
  <li>Verify that your application is "debuggable" in your manifest or <em>build.gradle</em> file.
    <p>In the build file, make sure the <em>debuggable</em> property in the <em>debug</em> build
    type is set to true. The build type property overrides the manifest setting. </p>
<pre>
android {
    buildTypes {
        debug {
            debuggable true
        }
</pre>

    <p>In the <code>AndroidManifest.xml</code> file, add <code>android:debuggable="true"</code> to
the <code>&lt;application></code> element.</p>
    <p class="note"><strong>Note:</strong> If you manually enable debugging in the manifest
 file, be sure to disable it in your release build (your published application
should usually <em>not</em> be debuggable).</p></li>
  <li>Enable <strong>USB debugging</strong> on your device.
    <ul>
      <li>On most devices running Android 3.2 or older, you can find the option under
        <strong>Settings > Applications > Development</strong>.</li>
      <li>On Android 4.0 and newer, it's in <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>
    </ul>
  </li>
  <li>Set up your system to detect your device.
    <ul>
      <li>If you're developing on Windows, you need to install a USB driver for adb. For an
installation guide and links to OEM drivers, see the <a href="{@docRoot}tools/extras/oem-usb.html">OEM USB
Drivers</a> document.</li>
      <li>If you're developing on Mac OS X, it just works. Skip this step.</li>
      <li>If you're developing on Ubuntu Linux, you need to add a
<code>udev</code> rules file that contains a USB configuration for each type of device
you want to use for development. In the rules file, each device manufacturer
is identified by a unique vendor ID, as specified by the
<code>ATTR{idVendor}</code> property. For a list of vendor IDs, see  <a
href="#VendorIds">USB Vendor IDs</a>, below. To set up device detection on
Ubuntu Linux:

        <ol type="a">
          <li>Log in as root and create this file:
            <code>/etc/udev/rules.d/51-android.rules</code></span>.
            <p>Use this format to add each vendor to the file:<br/>
              <code>SUBSYSTEM==&quot;usb&quot;, ATTR{idVendor}==&quot;0bb4&quot;, MODE=&quot;0666&quot;, GROUP=&quot;plugdev&quot;</code>
              <br /><br />

              In this example, the vendor ID is for HTC. The <code>MODE</code>
assignment specifies read/write permissions, and <code>GROUP</code> defines
which Unix group  owns the device node. </p>

            <p class="note"><strong>Note:</strong> The rule syntax
may vary slightly depending on your  environment. Consult the <code>udev</code>
documentation for your system as needed. For an overview of rule syntax, see
this guide to <a
href="http://www.reactivated.net/writing_udev_rules.html">writing udev
rules</a>.</p>
          </li>
          <li>Now execute:<br/>
            <code>chmod a+r /etc/udev/rules.d/51-android.rules</code>
          </li>
        </ol>
      </li>
    </ul>
  </li>
</ol>


<p class="note"><strong>Note:</strong> When you connect a device running Android 4.2.2 or higher
to your computer, the system shows a dialog asking whether to accept an RSA key that allows
debugging through this computer. This security mechanism protects user devices because it ensures
that USB debugging and other adb commands cannot be executed unless you're able to unlock the
device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with
SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or
higher.</p>


<p>When plugged in over USB, you can verify that your device is connected by executing <code>adb
devices</code> from your SDK {@code platform-tools/} directory. If connected,
you'll see the device name listed as a "device."</p>

<p>If using Android Studio, run or debug your application as usual. You will be
presented with a <b>Device Chooser</b> dialog that lists the available
emulator(s) and connected device(s). Select the device upon which you want to
install and run the application.</p>

<p>If using the <a href="{@docRoot}tools/help/adb.html">Android
Debug Bridge</a> (adb), you can issue commands with the <code>-d</code> flag to
target your connected device.</p>

<h3 id="VendorIds">USB Vendor IDs</h3>

<p>This table provides a reference to the vendor IDs needed in order to add USB
device support on Linux. The USB Vendor ID is the value given to the
<code>ATTR{idVendor}</code> property in the rules file, as described
above.</p>

<table>
  <tr>
    <th>Company</th><th>USB Vendor ID</th></tr>
  <tr>
    <td>Acer</td>
    <td><code>0502</code></td>
  </tr>
  <tr>
    <td>ASUS</td>
    <td><code>0b05</code></td>
  </tr>
  <tr>
    <td>Dell</td>
    <td><code>413c</code></td>
  </tr>
  <tr>
    <td>Foxconn</td>
    <td><code>0489</code></td>
  </tr>
  <tr>
    <td>Fujitsu</td>
    <td><code>04c5</code></td>
  </tr>
  <tr>
    <td>Fujitsu Toshiba</td>
    <td><code>04c5</code></td>
  </tr>
  <tr>
    <td>Garmin-Asus</td>
    <td><code>091e</code></td>
  </tr>
  <tr>
    <td>Google</td>
    <td><code>18d1</code></td>
  </tr>
  <tr>
    <td>Haier</td>
    <td><code>201E</code></td>
  </tr>
  <tr>
    <td>Hisense</td>
    <td><code>109b</code></td>
  </tr>
  <tr>
    <td>HTC</td>
    <td><code>0bb4</code></td>
  </tr>
  <tr>
    <td>Huawei</td>
    <td><code>12d1</code></td>
  </tr>
  <tr>
    <td>Intel</td>
    <td><code>8087</code></td>
  </tr>
  <tr>
    <td>K-Touch</td>
    <td><code>24e3</code></td>
  </tr>
  <tr>
    <td>KT Tech</td>
    <td><code>2116</code></td>
  </tr>
  <tr>
    <td>Kyocera</td>
    <td><code>0482</code></td>
  </tr>
  <tr>
    <td>Lenovo</td>
    <td><code>17ef</code></td>
  </tr>
  <tr>
    <td>LG</td>
    <td><code>1004</code></td>
  </tr>
  <tr>
    <td>Motorola</td>
    <td><code>22b8</code></td>
  </tr>
  <tr>
    <td>MTK</td>
    <td><code>0e8d</code></td>
  </tr>
  <tr>
    <td>NEC</td>
    <td><code>0409</code></td>
  </tr>
  <tr>
    <td>Nook</td>
    <td><code>2080</code></td>
  </tr>
  <tr>
    <td>Nvidia</td>
    <td><code>0955</code></td>
  </tr>
  <tr>
    <td>OTGV</td>
    <td><code>2257</code></td>
  </tr>
  <tr>
    <td>Pantech</td>
    <td><code>10a9</code></td>
  </tr>
  <tr>
    <td>Pegatron</td>
    <td><code>1d4d</code></td>
  </tr>
  <tr>
    <td>Philips</td>
    <td><code>0471</code></td>
  </tr>
  <tr>
    <td>PMC-Sierra</td>
    <td><code>04da</code></td>
  </tr>
  <tr>
    <td>Qualcomm</td>
    <td><code>05c6</code></td>
  </tr>
  <tr>
    <td>SK Telesys</td>
    <td><code>1f53</code></td>
  </tr>
  <tr>
    <td>Samsung</td>
    <td><code>04e8</code></td>
  </tr>
  <tr>
    <td>Sharp</td>
    <td><code>04dd</code></td>
  </tr>
  <tr>
    <td>Sony</td>
    <td><code>054c</code></td>
  </tr>
  <tr>
    <td>Sony Ericsson</td>
    <td><code>0fce</code></td>
  </tr>
  <tr>
    <td>Sony Mobile Communications</td>
    <td><code>0fce</code></td>
  </tr>
  <tr>
    <td>Teleepoch</td>
    <td><code>2340</code></td>
  </tr>
  <tr>
    <td>Toshiba</td>
    <td><code>0930</code></td>
  </tr>
  <tr>
    <td>ZTE</td>
    <td><code>19d2</code></td>
  </tr>
</table>