blob: ccd590337280b6ad0c260138608ac446bd94eea4 [file] [log] [blame]
Scott Main50e990c2012-06-21 17:14:39 -07001page.title=Using Hardware Devices
2@jd:body
3
4<div id="qv-wrapper">
5<div id="qv">
6 <h2>In this document</h2>
7 <ol>
8 <li><a href="#setting-up">Setting up a Device for Development</a>
9 <ol>
10 <li><a href="#VendorIds">USB Vendor IDs</a></li>
11 </ol>
12 </li>
13 </ol>
14 <h2>See also</h2>
15 <ol>
16 <li><a href="{@docRoot}sdk/win-usb.html">Google USB Driver</a></li>
17 <li><a href="{@docRoot}tools/extras/oem-usb.html">OEM USB Drivers</a></li>
18 </ol>
19</div>
20</div>
21
22<p>When building a mobile application, it's important that you always test your application on a
23real device before releasing it to users. This page describes how to set up your development
24environment and Android-powered device for testing and debugging on the device.</p>
25
26<p>You can use any Android-powered device as an environment for running,
27debugging, and testing your applications. The tools included in the SDK make it easy to install and
28run your application on the device each time you compile. You can install your application on the
29device directly from Eclipse or from the command line with ADB. If
30you don't yet have a device, check with the service providers in your area to determine which
31Android-powered devices are available.</p>
32
Ricardo Cervera7abf5cd2014-03-28 10:15:24 -070033<p>If you want a SIM-unlocked phone, then you might consider a Nexus phone. To purchase a
34Nexus phone, visit the <a href="https://play.google.com/store/devices">Google Play</a> store.</p>
Scott Main50e990c2012-06-21 17:14:39 -070035
36<p class="note"><strong>Note:</strong> When developing on a device, keep in mind that you should
37still use the <a
38href="{@docRoot}tools/devices/emulator.html">Android emulator</a> to test your
39application
40on configurations that are not equivalent to those of your real device. Although the emulator
41does not allow you to test every device feature (such as the accelerometer), it does
42allow you to verify that your application functions properly on different versions of the Android
43platform, in different screen sizes and orientations, and more.</p>
44
45
46<h2 id="setting-up">Setting up a Device for Development</h2>
47
48<p>With an Android-powered device, you can develop and debug your Android applications just as you
49would on the emulator. Before you can start, there are just a few things to do:</p>
50
51<ol>
52 <li>Declare your application as "debuggable" in your Android Manifest.
53 <p>When using Eclipse, you can skip this step, because running your app directly from
54the Eclipse IDE automatically enables debugging.</p>
55 <p>In the <code>AndroidManifest.xml</code> file, add <code>android:debuggable="true"</code> to
56the <code>&lt;application></code> element.</p>
57 <p class="note"><strong>Note:</strong> If you manually enable debugging in the manifest
58 file, be sure to disable it before you build for release (your published application
59should usually <em>not</em> be debuggable).</p></li>
Scott Mainda02c642012-10-11 14:37:59 -070060 <li>Enable <strong>USB debugging</strong> on your device.
61 <ul>
62 <li>On most devices running Android 3.2 or older, you can find the option under
63 <strong>Settings > Applications > Development</strong>.</li>
64 <li>On Android 4.0 and newer, it's in <strong>Settings > Developer options</strong>.
65 <p class="note"><strong>Note:</strong> On Android 4.2 and newer, <strong>Developer
66 options</strong> is hidden by default. To make it available, go
67 to <strong>Settings > About phone</strong> and tap <strong>Build number</strong>
68 seven times. Return to the previous screen to find <strong>Developer options</strong>.</p>
69 </li>
70 </ul>
Scott Main50e990c2012-06-21 17:14:39 -070071 </li>
72 <li>Set up your system to detect your device.
73 <ul>
74 <li>If you're developing on Windows, you need to install a USB driver for adb. For an
75installation guide and links to OEM drivers, see the <a href="{@docRoot}tools/extras/oem-usb.html">OEM USB
76Drivers</a> document.</li>
77 <li>If you're developing on Mac OS X, it just works. Skip this step.</li>
78 <li>If you're developing on Ubuntu Linux, you need to add a
79<code>udev</code> rules file that contains a USB configuration for each type of device
80you want to use for development. In the rules file, each device manufacturer
81is identified by a unique vendor ID, as specified by the
82<code>ATTR{idVendor}</code> property. For a list of vendor IDs, see <a
83href="#VendorIds">USB Vendor IDs</a>, below. To set up device detection on
84Ubuntu Linux:
85
86 <ol type="a">
87 <li>Log in as root and create this file:
88 <code>/etc/udev/rules.d/51-android.rules</code></span>.
89 <p>Use this format to add each vendor to the file:<br/>
90 <code>SUBSYSTEM==&quot;usb&quot;, ATTR{idVendor}==&quot;0bb4&quot;, MODE=&quot;0666&quot;, GROUP=&quot;plugdev&quot;</code>
91 <br /><br />
Ricardo Cervera7abf5cd2014-03-28 10:15:24 -070092
Scott Main50e990c2012-06-21 17:14:39 -070093 In this example, the vendor ID is for HTC. The <code>MODE</code>
94assignment specifies read/write permissions, and <code>GROUP</code> defines
95which Unix group owns the device node. </p>
Ricardo Cervera7abf5cd2014-03-28 10:15:24 -070096
Scott Main50e990c2012-06-21 17:14:39 -070097 <p class="note"><strong>Note:</strong> The rule syntax
98may vary slightly depending on your environment. Consult the <code>udev</code>
99documentation for your system as needed. For an overview of rule syntax, see
100this guide to <a
101href="http://www.reactivated.net/writing_udev_rules.html">writing udev
102rules</a>.</p>
103 </li>
104 <li>Now execute:<br/>
105 <code>chmod a+r /etc/udev/rules.d/51-android.rules</code>
106 </li>
107 </ol>
108 </li>
109 </ul>
110 </li>
111</ol>
112
Scott Main03c54e72013-02-05 14:05:36 -0800113
114<p class="note"><strong>Note:</strong> When you connect a device running Android 4.2.2 or higher
115to your computer, the system shows a dialog asking whether to accept an RSA key that allows
116debugging through this computer. This security mechanism protects user devices because it ensures
117that USB debugging and other adb commands cannot be executed unless you're able to unlock the
118device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with
119SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or
120higher.</p>
121
122
123<p>When plugged in over USB, you can verify that your device is connected by executing <code>adb
Scott Main50e990c2012-06-21 17:14:39 -0700124devices</code> from your SDK {@code platform-tools/} directory. If connected,
125you'll see the device name listed as a "device."</p>
126
127<p>If using Eclipse, run or debug your application as usual. You will be
128presented with a <b>Device Chooser</b> dialog that lists the available
129emulator(s) and connected device(s). Select the device upon which you want to
130install and run the application.</p>
131
132<p>If using the <a href="{@docRoot}tools/help/adb.html">Android
133Debug Bridge</a> (adb), you can issue commands with the <code>-d</code> flag to
134target your connected device.</p>
135
136<h3 id="VendorIds">USB Vendor IDs</h3>
137
138<p>This table provides a reference to the vendor IDs needed in order to add USB
139device support on Linux. The USB Vendor ID is the value given to the
Ricardo Cervera7abf5cd2014-03-28 10:15:24 -0700140<code>ATTR{idVendor}</code> property in the rules file, as described
Scott Main50e990c2012-06-21 17:14:39 -0700141above.</p>
142
143<table>
144 <tr>
145 <th>Company</th><th>USB Vendor ID</th></tr>
146 <tr>
147 <td>Acer</td>
148 <td><code>0502</code></td>
149 </tr>
150 <tr>
151 <td>ASUS</td>
152 <td><code>0b05</code></td>
153 </tr>
154 <tr>
155 <td>Dell</td>
156 <td><code>413c</code></td>
157 </tr>
158 <tr>
159 <td>Foxconn</td>
160 <td><code>0489</code></td>
161 </tr>
162 <tr>
163 <td>Fujitsu</td>
164 <td><code>04c5</code></td>
165 </tr>
166 <tr>
167 <td>Fujitsu Toshiba</td>
168 <td><code>04c5</code></td>
169 </tr>
170 <tr>
171 <td>Garmin-Asus</td>
172 <td><code>091e</code></td>
173 </tr>
174 <tr>
175 <td>Google</td>
176 <td><code>18d1</code></td>
177 </tr>
178 <tr>
Scott Main2cc84c62013-05-22 08:34:49 -0700179 <td>Haier</td>
180 <td><code>201E</code></td>
181 </tr>
182 <tr>
Scott Main50e990c2012-06-21 17:14:39 -0700183 <td>Hisense</td>
184 <td><code>109b</code></td>
185 </tr>
186 <tr>
187 <td>HTC</td>
188 <td><code>0bb4</code></td>
189 </tr>
190 <tr>
191 <td>Huawei</td>
192 <td><code>12d1</code></td>
193 </tr>
194 <tr>
195 <td>K-Touch</td>
196 <td><code>24e3</code></td>
197 </tr>
198 <tr>
199 <td>KT Tech</td>
200 <td><code>2116</code></td>
201 </tr>
202 <tr>
203 <td>Kyocera</td>
204 <td><code>0482</code></td>
205 </tr>
206 <tr>
207 <td>Lenovo</td>
208 <td><code>17ef</code></td>
209 </tr>
210 <tr>
211 <td>LG</td>
212 <td><code>1004</code></td>
213 </tr>
214 <tr>
215 <td>Motorola</td>
216 <td><code>22b8</code></td>
217 </tr>
218 <tr>
Scott Main1649f812013-02-26 09:45:13 -0800219 <td>MTK</td>
220 <td><code>0e8d</code></td>
221 </tr>
222 <tr>
Scott Main50e990c2012-06-21 17:14:39 -0700223 <td>NEC</td>
224 <td><code>0409</code></td>
225 </tr>
226 <tr>
227 <td>Nook</td>
228 <td><code>2080</code></td>
229 </tr>
230 <tr>
231 <td>Nvidia</td>
232 <td><code>0955</code></td>
233 </tr>
234 <tr>
235 <td>OTGV</td>
236 <td><code>2257</code></td>
237 </tr>
238 <tr>
239 <td>Pantech</td>
240 <td><code>10a9</code></td>
241 </tr>
242 <tr>
243 <td>Pegatron</td>
244 <td><code>1d4d</code></td>
245 </tr>
246 <tr>
247 <td>Philips</td>
248 <td><code>0471</code></td>
249 </tr>
250 <tr>
251 <td>PMC-Sierra</td>
252 <td><code>04da</code></td>
253 </tr>
254 <tr>
255 <td>Qualcomm</td>
256 <td><code>05c6</code></td>
257 </tr>
258 <tr>
259 <td>SK Telesys</td>
260 <td><code>1f53</code></td>
261 </tr>
262 <tr>
263 <td>Samsung</td>
264 <td><code>04e8</code></td>
265 </tr>
266 <tr>
267 <td>Sharp</td>
268 <td><code>04dd</code></td>
269 </tr>
270 <tr>
271 <td>Sony</td>
272 <td><code>054c</code></td>
273 </tr>
274 <tr>
275 <td>Sony Ericsson</td>
276 <td><code>0fce</code></td>
277 </tr>
278 <tr>
279 <td>Teleepoch</td>
280 <td><code>2340</code></td>
281 </tr>
282 <tr>
283 <td>Toshiba</td>
284 <td><code>0930</code></td>
285 </tr>
286 <tr>
287 <td>ZTE</td>
288 <td><code>19d2</code></td>
289 </tr>
290</table>