Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 1 | page.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> |
smain@google.com | 78219f0 | 2014-06-13 11:39:35 -0700 | [diff] [blame] | 8 | <li><a href="#device-developer-options">Enabling On-device Developer Options</a></li> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 9 | <li><a href="#setting-up">Setting up a Device for Development</a> |
| 10 | <ol> |
| 11 | <li><a href="#VendorIds">USB Vendor IDs</a></li> |
| 12 | </ol> |
| 13 | </li> |
| 14 | </ol> |
| 15 | <h2>See also</h2> |
| 16 | <ol> |
| 17 | <li><a href="{@docRoot}sdk/win-usb.html">Google USB Driver</a></li> |
| 18 | <li><a href="{@docRoot}tools/extras/oem-usb.html">OEM USB Drivers</a></li> |
| 19 | </ol> |
| 20 | </div> |
| 21 | </div> |
| 22 | |
| 23 | <p>When building a mobile application, it's important that you always test your application on a |
| 24 | real device before releasing it to users. This page describes how to set up your development |
| 25 | environment and Android-powered device for testing and debugging on the device.</p> |
| 26 | |
| 27 | <p>You can use any Android-powered device as an environment for running, |
| 28 | debugging, and testing your applications. The tools included in the SDK make it easy to install and |
| 29 | run your application on the device each time you compile. You can install your application on the |
Rich Slogar | daaa164 | 2014-11-07 13:26:17 -0800 | [diff] [blame] | 30 | device directly from Android Studio or from the command line with ADB. If |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 31 | you don't yet have a device, check with the service providers in your area to determine which |
| 32 | Android-powered devices are available.</p> |
| 33 | |
Ricardo Cervera | 7abf5cd | 2014-03-28 10:15:24 -0700 | [diff] [blame] | 34 | <p>If you want a SIM-unlocked phone, then you might consider a Nexus phone. To purchase a |
| 35 | Nexus phone, visit the <a href="https://play.google.com/store/devices">Google Play</a> store.</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 36 | |
| 37 | <p class="note"><strong>Note:</strong> When developing on a device, keep in mind that you should |
| 38 | still use the <a |
| 39 | href="{@docRoot}tools/devices/emulator.html">Android emulator</a> to test your |
| 40 | application |
| 41 | on configurations that are not equivalent to those of your real device. Although the emulator |
| 42 | does not allow you to test every device feature (such as the accelerometer), it does |
| 43 | allow you to verify that your application functions properly on different versions of the Android |
| 44 | platform, in different screen sizes and orientations, and more.</p> |
| 45 | |
| 46 | |
smain@google.com | 78219f0 | 2014-06-13 11:39:35 -0700 | [diff] [blame] | 47 | <h2 id="developer-device-options" style="margin-bottom: 0px;">Enabling On-device Developer Options</h2> |
| 48 | |
| 49 | <img src="/images/tools/dev-options-inmilk.png" alt="" style="float:right;margin-left:30px"> |
| 50 | |
| 51 | <p>Android-powered devices have a host of developer options that you can |
| 52 | access on the phone, which let you:</p> |
| 53 | <ul> |
| 54 | <li>Enable debugging over USB.</li> |
| 55 | <li>Quickly capture bug reports onto the device.</li> |
| 56 | <li>Show CPU usage on screen.</li> |
| 57 | <li>Draw debugging information on screen such as layout bounds, |
| 58 | updates on GPU views and hardware layers, and other information.</li> |
| 59 | <li>Plus many more options to simulate app stresses or enable debugging options.</li> |
| 60 | </ul> |
| 61 | <p>To access these settings, open the <em>Developer options</em> in the |
Joe Fernandez | 7adb4c8 | 2016-03-28 10:04:57 -0700 | [diff] [blame] | 62 | system Settings. On Android 4.2 and higher, the <strong>Developer options</strong> screen is |
smain@google.com | 78219f0 | 2014-06-13 11:39:35 -0700 | [diff] [blame] | 63 | hidden by default. To make it visible, go to |
| 64 | <b>Settings > About phone</b> and tap <b>Build number</b> seven times. Return to the previous |
Joe Fernandez | 7adb4c8 | 2016-03-28 10:04:57 -0700 | [diff] [blame] | 65 | screen to find <strong>Developer options</strong> at the bottom.</p> |
smain@google.com | 78219f0 | 2014-06-13 11:39:35 -0700 | [diff] [blame] | 66 | |
| 67 | |
| 68 | |
| 69 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 70 | <h2 id="setting-up">Setting up a Device for Development</h2> |
| 71 | |
| 72 | <p>With an Android-powered device, you can develop and debug your Android applications just as you |
| 73 | would on the emulator. Before you can start, there are just a few things to do:</p> |
| 74 | |
| 75 | <ol> |
Rich Slogar | daaa164 | 2014-11-07 13:26:17 -0800 | [diff] [blame] | 76 | <li>Verify that your application is "debuggable" in your manifest or <em>build.gradle</em> file. |
| 77 | <p>In the build file, make sure the <em>debuggable</em> property in the <em>debug</em> build |
| 78 | type is set to true. The build type property overrides the manifest setting. </p> |
| 79 | <pre> |
| 80 | android { |
| 81 | buildTypes { |
| 82 | debug { |
| 83 | debuggable true |
| 84 | } |
| 85 | </pre> |
| 86 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 87 | <p>In the <code>AndroidManifest.xml</code> file, add <code>android:debuggable="true"</code> to |
| 88 | the <code><application></code> element.</p> |
| 89 | <p class="note"><strong>Note:</strong> If you manually enable debugging in the manifest |
Rich Slogar | daaa164 | 2014-11-07 13:26:17 -0800 | [diff] [blame] | 90 | file, be sure to disable it in your release build (your published application |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 91 | should usually <em>not</em> be debuggable).</p></li> |
Joe Fernandez | 7adb4c8 | 2016-03-28 10:04:57 -0700 | [diff] [blame] | 92 | <li>Enable <strong>USB debugging</strong> on your device by going to |
| 93 | <strong>Settings > Developer options</strong>. |
| 94 | <p class="note"><strong>Note:</strong> On Android 4.2 and newer, <strong>Developer |
Scott Main | da02c64 | 2012-10-11 14:37:59 -0700 | [diff] [blame] | 95 | options</strong> is hidden by default. To make it available, go |
| 96 | to <strong>Settings > About phone</strong> and tap <strong>Build number</strong> |
| 97 | seven times. Return to the previous screen to find <strong>Developer options</strong>.</p> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 98 | </li> |
| 99 | <li>Set up your system to detect your device. |
| 100 | <ul> |
| 101 | <li>If you're developing on Windows, you need to install a USB driver for adb. For an |
| 102 | installation guide and links to OEM drivers, see the <a href="{@docRoot}tools/extras/oem-usb.html">OEM USB |
| 103 | Drivers</a> document.</li> |
| 104 | <li>If you're developing on Mac OS X, it just works. Skip this step.</li> |
| 105 | <li>If you're developing on Ubuntu Linux, you need to add a |
| 106 | <code>udev</code> rules file that contains a USB configuration for each type of device |
| 107 | you want to use for development. In the rules file, each device manufacturer |
| 108 | is identified by a unique vendor ID, as specified by the |
| 109 | <code>ATTR{idVendor}</code> property. For a list of vendor IDs, see <a |
| 110 | href="#VendorIds">USB Vendor IDs</a>, below. To set up device detection on |
| 111 | Ubuntu Linux: |
| 112 | |
| 113 | <ol type="a"> |
| 114 | <li>Log in as root and create this file: |
| 115 | <code>/etc/udev/rules.d/51-android.rules</code></span>. |
| 116 | <p>Use this format to add each vendor to the file:<br/> |
| 117 | <code>SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"</code> |
| 118 | <br /><br /> |
Ricardo Cervera | 7abf5cd | 2014-03-28 10:15:24 -0700 | [diff] [blame] | 119 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 120 | In this example, the vendor ID is for HTC. The <code>MODE</code> |
| 121 | assignment specifies read/write permissions, and <code>GROUP</code> defines |
| 122 | which Unix group owns the device node. </p> |
Ricardo Cervera | 7abf5cd | 2014-03-28 10:15:24 -0700 | [diff] [blame] | 123 | |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 124 | <p class="note"><strong>Note:</strong> The rule syntax |
| 125 | may vary slightly depending on your environment. Consult the <code>udev</code> |
| 126 | documentation for your system as needed. For an overview of rule syntax, see |
| 127 | this guide to <a |
| 128 | href="http://www.reactivated.net/writing_udev_rules.html">writing udev |
| 129 | rules</a>.</p> |
| 130 | </li> |
| 131 | <li>Now execute:<br/> |
| 132 | <code>chmod a+r /etc/udev/rules.d/51-android.rules</code> |
| 133 | </li> |
| 134 | </ol> |
| 135 | </li> |
| 136 | </ul> |
| 137 | </li> |
| 138 | </ol> |
| 139 | |
Scott Main | 03c54e7 | 2013-02-05 14:05:36 -0800 | [diff] [blame] | 140 | |
| 141 | <p class="note"><strong>Note:</strong> When you connect a device running Android 4.2.2 or higher |
| 142 | to your computer, the system shows a dialog asking whether to accept an RSA key that allows |
| 143 | debugging through this computer. This security mechanism protects user devices because it ensures |
| 144 | that USB debugging and other adb commands cannot be executed unless you're able to unlock the |
| 145 | device and acknowledge the dialog. This requires that you have adb version 1.0.31 (available with |
| 146 | SDK Platform-tools r16.0.1 and higher) in order to debug on a device running Android 4.2.2 or |
| 147 | higher.</p> |
| 148 | |
| 149 | |
| 150 | <p>When plugged in over USB, you can verify that your device is connected by executing <code>adb |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 151 | devices</code> from your SDK {@code platform-tools/} directory. If connected, |
| 152 | you'll see the device name listed as a "device."</p> |
| 153 | |
Rich Slogar | daaa164 | 2014-11-07 13:26:17 -0800 | [diff] [blame] | 154 | <p>If using Android Studio, run or debug your application as usual. You will be |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 155 | presented with a <b>Device Chooser</b> dialog that lists the available |
| 156 | emulator(s) and connected device(s). Select the device upon which you want to |
| 157 | install and run the application.</p> |
| 158 | |
| 159 | <p>If using the <a href="{@docRoot}tools/help/adb.html">Android |
| 160 | Debug Bridge</a> (adb), you can issue commands with the <code>-d</code> flag to |
| 161 | target your connected device.</p> |
| 162 | |
| 163 | <h3 id="VendorIds">USB Vendor IDs</h3> |
| 164 | |
| 165 | <p>This table provides a reference to the vendor IDs needed in order to add USB |
| 166 | device support on Linux. The USB Vendor ID is the value given to the |
Ricardo Cervera | 7abf5cd | 2014-03-28 10:15:24 -0700 | [diff] [blame] | 167 | <code>ATTR{idVendor}</code> property in the rules file, as described |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 168 | above.</p> |
| 169 | |
| 170 | <table> |
| 171 | <tr> |
| 172 | <th>Company</th><th>USB Vendor ID</th></tr> |
| 173 | <tr> |
| 174 | <td>Acer</td> |
| 175 | <td><code>0502</code></td> |
| 176 | </tr> |
| 177 | <tr> |
| 178 | <td>ASUS</td> |
| 179 | <td><code>0b05</code></td> |
| 180 | </tr> |
| 181 | <tr> |
| 182 | <td>Dell</td> |
| 183 | <td><code>413c</code></td> |
| 184 | </tr> |
| 185 | <tr> |
| 186 | <td>Foxconn</td> |
| 187 | <td><code>0489</code></td> |
| 188 | </tr> |
| 189 | <tr> |
| 190 | <td>Fujitsu</td> |
| 191 | <td><code>04c5</code></td> |
| 192 | </tr> |
| 193 | <tr> |
| 194 | <td>Fujitsu Toshiba</td> |
| 195 | <td><code>04c5</code></td> |
| 196 | </tr> |
| 197 | <tr> |
| 198 | <td>Garmin-Asus</td> |
| 199 | <td><code>091e</code></td> |
| 200 | </tr> |
| 201 | <tr> |
| 202 | <td>Google</td> |
| 203 | <td><code>18d1</code></td> |
| 204 | </tr> |
| 205 | <tr> |
Scott Main | 2cc84c6 | 2013-05-22 08:34:49 -0700 | [diff] [blame] | 206 | <td>Haier</td> |
| 207 | <td><code>201E</code></td> |
| 208 | </tr> |
| 209 | <tr> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 210 | <td>Hisense</td> |
| 211 | <td><code>109b</code></td> |
| 212 | </tr> |
| 213 | <tr> |
Kevin Hufnagle | 9ee8d41 | 2016-04-25 12:00:01 -0700 | [diff] [blame] | 214 | <td>HP</td> |
| 215 | <td><code>03f0</code></td> |
| 216 | </tr> |
| 217 | <tr> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 218 | <td>HTC</td> |
| 219 | <td><code>0bb4</code></td> |
| 220 | </tr> |
| 221 | <tr> |
| 222 | <td>Huawei</td> |
| 223 | <td><code>12d1</code></td> |
| 224 | </tr> |
| 225 | <tr> |
Scott Main | 5584601 | 2014-05-02 10:50:50 -0700 | [diff] [blame] | 226 | <td>Intel</td> |
| 227 | <td><code>8087</code></td> |
| 228 | </tr> |
| 229 | <tr> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 230 | <td>K-Touch</td> |
| 231 | <td><code>24e3</code></td> |
| 232 | </tr> |
| 233 | <tr> |
| 234 | <td>KT Tech</td> |
| 235 | <td><code>2116</code></td> |
| 236 | </tr> |
| 237 | <tr> |
| 238 | <td>Kyocera</td> |
| 239 | <td><code>0482</code></td> |
| 240 | </tr> |
| 241 | <tr> |
| 242 | <td>Lenovo</td> |
| 243 | <td><code>17ef</code></td> |
| 244 | </tr> |
| 245 | <tr> |
| 246 | <td>LG</td> |
| 247 | <td><code>1004</code></td> |
| 248 | </tr> |
| 249 | <tr> |
| 250 | <td>Motorola</td> |
| 251 | <td><code>22b8</code></td> |
| 252 | </tr> |
| 253 | <tr> |
Scott Main | 1649f81 | 2013-02-26 09:45:13 -0800 | [diff] [blame] | 254 | <td>MTK</td> |
| 255 | <td><code>0e8d</code></td> |
| 256 | </tr> |
| 257 | <tr> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 258 | <td>NEC</td> |
| 259 | <td><code>0409</code></td> |
| 260 | </tr> |
| 261 | <tr> |
| 262 | <td>Nook</td> |
| 263 | <td><code>2080</code></td> |
| 264 | </tr> |
| 265 | <tr> |
| 266 | <td>Nvidia</td> |
| 267 | <td><code>0955</code></td> |
| 268 | </tr> |
| 269 | <tr> |
| 270 | <td>OTGV</td> |
| 271 | <td><code>2257</code></td> |
| 272 | </tr> |
| 273 | <tr> |
| 274 | <td>Pantech</td> |
| 275 | <td><code>10a9</code></td> |
| 276 | </tr> |
| 277 | <tr> |
| 278 | <td>Pegatron</td> |
| 279 | <td><code>1d4d</code></td> |
| 280 | </tr> |
| 281 | <tr> |
| 282 | <td>Philips</td> |
| 283 | <td><code>0471</code></td> |
| 284 | </tr> |
| 285 | <tr> |
| 286 | <td>PMC-Sierra</td> |
| 287 | <td><code>04da</code></td> |
| 288 | </tr> |
| 289 | <tr> |
| 290 | <td>Qualcomm</td> |
| 291 | <td><code>05c6</code></td> |
| 292 | </tr> |
| 293 | <tr> |
| 294 | <td>SK Telesys</td> |
| 295 | <td><code>1f53</code></td> |
| 296 | </tr> |
| 297 | <tr> |
| 298 | <td>Samsung</td> |
| 299 | <td><code>04e8</code></td> |
| 300 | </tr> |
| 301 | <tr> |
| 302 | <td>Sharp</td> |
| 303 | <td><code>04dd</code></td> |
| 304 | </tr> |
| 305 | <tr> |
| 306 | <td>Sony</td> |
| 307 | <td><code>054c</code></td> |
| 308 | </tr> |
| 309 | <tr> |
| 310 | <td>Sony Ericsson</td> |
| 311 | <td><code>0fce</code></td> |
| 312 | </tr> |
| 313 | <tr> |
Andrew Solovay | be39d67 | 2014-05-30 15:15:49 -0700 | [diff] [blame] | 314 | <td>Sony Mobile Communications</td> |
| 315 | <td><code>0fce</code></td> |
| 316 | </tr> |
| 317 | <tr> |
Scott Main | 50e990c | 2012-06-21 17:14:39 -0700 | [diff] [blame] | 318 | <td>Teleepoch</td> |
| 319 | <td><code>2340</code></td> |
| 320 | </tr> |
| 321 | <tr> |
| 322 | <td>Toshiba</td> |
| 323 | <td><code>0930</code></td> |
| 324 | </tr> |
| 325 | <tr> |
| 326 | <td>ZTE</td> |
| 327 | <td><code>19d2</code></td> |
| 328 | </tr> |
| 329 | </table> |