前面的话

写这篇译文,主要是因为几年前写过的一篇博客《关于adb命令没有权限访问手机设备的问题》,博客地址如下:
http://blog.csdn.net/liubingzhao/article/details/13050845
我平时写博客相对较少,但这篇却有5000+的访问量,对于技术大咖来说可能不算高,但对于我来说比较可观了,考虑到Android官网在墙外,所以有想把它翻译到博客的冲动。
官方原文地址:https://developer.android.com/studio/run/device.html
开始吧!

正文

When building an Android app, 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.
开发Android应用程序时,在应用发布之前,你需要时不时在实体机上测试自己的应用。本页就介绍如何配置开发环境和Android设备,以便在设备上进行测试和调试。

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.
您可以使用任何Android设备作为运行、调试和测试应用程序的环境。 SDK中包含的工具使得每次编译时都很容易在设备上安装和运行应用。 您可以直接在Android Studio上将程序安装到设备,也可使用ADB命令行。如果您还没有设备,请与您所在地区的服务提供商联系,确定哪些Android设备可用。

If you want a SIM-unlocked phone, then you might consider a Nexus phone. To purchase a Nexus phone, visit the Google Play store.
如果您想使用无锁机,则可以考虑使用Nexus手机。 要购买Nexus手机,请访问Google Play商店。(这些咱就当没看见,略过)

Note: When developing on a device, keep in mind that you should still use the Android emulator 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, 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.
注意:在设备上开发时,请记住,您仍然需使用与真实设备不同配置的Android模拟器上测试应用程序。 虽然你不能在模拟器上测试每个设备功能,但它允许你验证你的应用程序在不同版本的Android平台上能正常运行,如不同的屏幕大小和方向等。

Enabling On-device Developer Options 启用设备上开发人员选项

Android-powered devices have a host of developer options that you can access on the phone, which let you:
Android设备拥有多种开发人员选项,你可以通过手机访问这些选项,你可以:

  • Enable debugging over USB.
    通过USB启用调试
  • Quickly capture bug reports onto the device.
    快速捕获设备上的错误报告。
  • Show CPU usage on screen.
    在屏幕上显示CPU使用率。
  • Draw debugging information on screen such as layout bounds, updates on GPU views and hardware layers, and other information.
    在屏幕上绘制调试信息,如布局边界,GPU视图层和硬件层的刷新,以及其他信息。
  • Plus many more options to simulate app stresses or enable debugging options.
    还有更多的选项来模拟应用程序压力或启用调试选项。

    To access these settings, open the Developer options in the system Settings. On Android 4.2 and higher, the Developer options screen is hidden by default. To make it visible, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options at the bottom.
    要访问这些设置,请打开系统设置中的开发人员选项。 在Android 4.2及更高版本中,默认情况下是隐藏开发人员选项的。 要使其可见,请到设置 > 关于手机,然后点击版本号七次。 返回上一个屏幕,在底部即可找到开发人员选项

Setting up a Device for Development 配置开发设备

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:
使用Android设备,您可以像在模拟器上一样开发和调试Android应用程序。 在你可以开始之前,只有几个事情要做:

  1. Verify that your application is “debuggable” in your manifest or build.gradle file.
    确定你的应用程序的manifest或build.gradle文件中是“debuggable”。
    In the build file, make sure the debuggable property in the debug build type is set to true. The build type property overrides the manifest setting.
    在build文件中,确保调试构建类型中的debuggable属性设置为true。 构建类型属性覆盖manifest中的设置。

    android {buildTypes {debug {debuggable true}

    In the AndroidManifest.xml file, add android:debuggable="true" to the <application> element.
    AndroidManifest.xml文件中,添加android:debuggable="true"<application>元素中。
    Note: If you manually enable debugging in the manifest file, be sure to disable it in your release build (your published application should usually not be debuggable).
    注意:如果在manifest文件中手动启用调试,请确保在发布版本中禁用它(已发布的应用程序通常不可调试)。

  2. Enable USB debugging in the device system settings, under Settings > Developer options.
    在设备系统设置中的设置>开发人员选项下启用USB调试。
    Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
    注意:在Android 4.2及更高版本中,默认情况下隐藏开发者选项。 要使其可用,请到设置 > 关于手机,然后点击版本号七次。 返回上一个屏幕便可找到开发人员选项

  3. Set up your system to detect your device.配置系统以检测到你的设备。

    • 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 OEM USB Drivers document.
      如果你在Windows上开发,你需要为adb安装USB驱动程序。 有关安装指南和设备制造商驱动程序的链接,请参阅设备制造商的USB驱动程序文档。
    • If you’re developing on Mac OS X, it just works. Skip this step.
      如果你在Mac OS X上开发,它可正常工作。 跳过此步骤。
    • If you’re developing on Ubuntu Linux, you need to add a udev 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 ATTR{idVendor} property. For a list of vendor IDs, see USB Vendor IDs, below. To set up device detection on Ubuntu Linux:
      如果你在Ubuntu Linux上开发,你需要添加一个udev规则文件,其中包含要用于开发的每种类型的设备的USB配置。 在规则文件中,每个设备制造商由唯一的供应商ID标识,由ATTR {idVendor}属性指定。 有关供应商ID的列表,请参阅下面的USB供应商ID。 要在Ubuntu Linux上设置设备检测:
      a. Log in as root and create this file: /etc/udev/rules.d/51-android.rules.
      以root身份登录并创建此文件:/etc/udev/rules.d/51-android.rules
      Use this format to add each vendor to the file:
      使用此格式将每个供应商添加到文件中:

      SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

      In this example, the vendor ID is for HTC. The MODE assignment specifies read/write permissions, and GROUP defines which Unix group owns the device node.
      在此示例中,供应商ID为HTC的。 MODE分配指定读/写权限,GROUP定义哪个Unix组拥有设备节点。
      Note: The rule syntax may vary slightly depending on your environment. Consult the udev documentation for your system as needed. For an overview of rule syntax, see this guide to writing udev rules.
      注意:根据您的环境,规则语法可能略有不同。 根据需要查看系统的udev文档。 有关规则语法的概述,请参阅本指南以编写udev规则。
      b. Now execute:
      现在执行:

      chmod a+r /etc/udev/rules.d/51-android.rules

Note: 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.
注意:当您将Android 4.2.2或更高版本的设备连接到计算机时,系统会显示一个对话框,询问是否允许通过此计算机进行调试的RSA密钥。 此安全机制保护用户设备,因为它确保无法执行USB调试和其他adb命令,除非您能解锁设备并确认对话框。 这需要你有adb版本1.0.31(适用于SDK Platform-tools r16.0.1及更高版本),以便在Android 4.2.2或更高版本的设备上进行调试。

When plugged in over USB, you can verify that your device is connected by executing adb devices from your SDK platform-tools/ directory. If connected, you’ll see the device name listed as a “device.”
USB插入时,您可以通过从SDK platform-tools/目录执行adb devices来验证设备是否已连接。 如果已连接,你会看到作为“设备”列出的设备名称。

If using Android Studio, run or debug your application as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s). Select the device upon which you want to install and run the application.
如果使用Android Studio,像平时一样运行或调试你的应用程序。 您将看到一个设备选择器对话框,其中列出了可用的模拟器和连接的设备。 选择要安装和运行应用程序的设备。

If using the Android Debug Bridge (adb), you can issue commands with the -d flag to target your connected device.
如果使用Android Debug Bridge(adb),你可以使用带-d标志的命令,以定位连接的设备。

USB Vendor IDs. USB供应商ID

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 ATTR{idVendor} property in the rules file, as described above.
此表提供了对在Linux上添加USB设备支持所需的供应商ID的引用。 USB供应商ID是给定到规则文件中的ATTR {idVendor}属性的值,如上所述。

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

Configuring USB Access 配置USB访问

此段原文地址:http://source.android.com/source/initializing.html#configuring-usb-access

Under GNU/Linux systems (and specifically under Ubuntu systems), regular users can’t directly access USB devices by default. The system needs to be configured to allow such access.
在GNU / Linux系统下(特别是在Ubuntu系统下),普通用户默认情况下不能直接访问USB设备。 系统需要配置为允许此类访问。

The recommended approach is to create a file at /etc/udev/rules.d/51-android.rules (as the root user).
建议的方法是在/etc/udev/rules.d/51-android.rules(作为root用户操作)上创建一个文件。

To do this, run the following command to download the 51-android.rules file attached to this site, modify it to include your username, and place it in the correct location:
为此,运行以下命令,到此网站下载51-android.rules文件,修改它以包括你的用户名,并将其放置在正确的路径:

$ wget -S -O - http://source.android.com/source/51-android.rules | sed "s/<username>/$USER/" | sudo tee >/dev/null /etc/udev/rules.d/51-android.rules; sudo udevadm control --reload-rules

Those new rules take effect the next time a device is plugged in. It might therefore be necessary to unplug the device and plug it back into the computer.
这些新规则将在下次插入设备时生效。因此,可能需要重新插拔设备。

看到墙外的站点源http://source.android.com/source/51-android.rules,多少感觉有些遗憾,其实这个文件内容如下:

# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER=""
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER=""
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER=""
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER=""
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER=""
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER=""
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER=""
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER=""
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER=""
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER=""
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER=""
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER=""
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER=""
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER=""
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER=""
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER=""
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER=""
# adb protocol on hammerhead (Nexus 5)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee1", MODE="0600", OWNER=""

看完之后又不觉得有啥遗憾,因为咱基本不用这些手机,o(∩∩)o…哈哈。又回到本文开始的那句话了,如果不知道怎么配置咱自己的51-android.rules文件,那就看看这篇博文:关于adb命令没有权限访问手机设备的问题

这算的上是我在CSDN上第一篇翻译作品,作为一名程序员、一名英语爱好者,觉得翻译自己专业相关的文章还是挺有意思的,希望您多支持、多指教。

【完】

在硬件设备上运行Android应用程序相关推荐

  1. anbox 使用情况_Anbox让您在Linux桌面上运行Android应用程序

    Anbox让您在Linux桌面上运行Android应用程序 imcn 2017年4月13日 1条评论 阅读 18,083 次 认识一下Anbox,一种新颖的在Linux桌面上运行Android应用的新 ...

  2. android phone win10下载,微软Your Phone新功能: 可在Win 10 PC 上运行 Android 应用程序...

    今年 8 月,微软发布了一项 Your Phone 重大功能,可以在 Windows 10 PC 上运行 Android 应用程序.该功能主要通过 Your Phone 应用将 Android 应用投 ...

  3. 手把手教程 | 使用 NICE DCV 在 G4 实例上运行 Android 应用程序

    随着Android应用程序和游戏变得越来越丰富,其中有些甚至比PC上的软件更易于使用和娱乐,因此许多人希望能够在云上运行Android游戏或应用程序,而在EC2实例上运行Android的解决方案可以让 ...

  4. 打破平台限制,小程序如何在硬件设备上运行?

    在小程序技术日益成熟.生态日益善的前景下,运营者们发现小程序"即用即走.轻量开发"的特点非常契合各种硬件设备的使用场景:开发者们对"一次开发,多端运行"的诉求也 ...

  5. 使用Anbox在Jetson Nano 2GB上运行Android应用程序

    目录 1. 重新编译并烧写Jetson Nano 2GB内核 1.1 获取kernel源代码 1.2 编译并烧写内核 2. 更新libsdl2库 3. 编译安装Anbox Jetson Nano 2G ...

  6. 微软程序在Android上跑,想在Win 10上运行Android应用?这类手机用户已经可以尝鲜...

    在Win 10上运行Android应用?这听起来有些异想天开,可实实在在的需求却在这里,毕竟微软Windows体系内的无缝切换,离开了手机平台始终有些怪怪的,自然,微软也不会甘心放弃,最好的办法,莫过 ...

  7. iPhone开发入门(10)— 设备上运行程序

    博主:易飞扬 原文链接 : http://www.yifeiyang.net/introduction-to-iphone-development-10-devices-running-the-pro ...

  8. 安卓虚拟linux系统教程,在Linux上模拟Android应用程序的3种方法 | MOS86

    如果您是Android的忠实拥护者,那么您可能已经知道自己最喜欢的移动操作系统是Linux. 过去我们已经介绍了Android如何基于开放源代码组件,Android真的是开放源代码吗? Android ...

  9. iOS从零开始使用Swift:如何在设备上测试iOS应用程序

    为初学者配置应用程序以在物理设备上进行测试或分发给App Store可能是一场噩梦. 但是,每个iOS开发人员都必须解决这一障碍. 在本文中,我对如何为物理设备上的测试提供应用程序提供了很好的理解. ...

最新文章

  1. 「工科神器」MATLAB风波未平,「化学神器」ChemOffice再爆清查国内盗版行为
  2. 谈国内软件测试盲点和与国外的差别
  3. 常见问题—打包压缩问题
  4. 现代控制理论第八版第二章读书笔记
  5. 灵光一现的创造——霍夫曼编码
  6. Reactive Extensions 相见恨晚的Rx.Net
  7. java的scanner的方法_Java Scanner reset()方法
  8. spark简介(大数据技术)
  9. SpringBoot学习——@Autowired自动注入报:could not be found问题的理解和解决方案
  10. visual设计的界面发布到iis上显示不一样_享声 SOUNDAWARE 发布可“全民HIFI“的网播一体机 A1...
  11. GaussDB分布式Stream执行计划详解
  12. scala编程第16章学习笔记(3)——List类的高阶方法
  13. HTML(八)------ 布局
  14. 立方单位换算计算机,体积单位换算
  15. 由中国银联主导和推行的“盒子支付模式”正式推出多平台应用
  16. 域策略(4)——设置统一锁屏壁纸(此策略仅适用于企业版、教育版和 Server SKU版)
  17. html复制标签快捷键,ps复制快捷键ctrl加什么
  18. 路由器php系统时间设置时间设置时间设置,4G工业路由器系统设置与时间密码设置...
  19. 有一种爱,我们不能称之为爱情
  20. Linux安装水星MW150US

热门文章

  1. 征服者蒙面侠c380更新升级_LOL9.3&9.4版本改动浅析:征服者搅动风云 暴击回调上线...
  2. IE浏览器字体兼容笔记
  3. Java开发Twitter爬虫抓取图片和视频并保存到本地
  4. WSL/Windows Subsystem for Linux based on PICO
  5. 电脑导入mobi书籍文件到IPAD的方法
  6. Acrobat9.0激活方法
  7. 用aiml构建英语聊天机器人
  8. 【MariaDB】浅谈 MariaDB 数据库
  9. CSS3动画制作的旋转风车,大家五一节日快乐
  10. ThinkPad T430i 愉快安装 Windows11