调试 Wear OS 应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需在实体手表上调试 Wear OS 应用,请使用 Wi-Fi 或蓝牙将开发机器连接到手表。如果您的手表有 USB 端口,也可以通过 USB 进行连接。
您还可以测试涉及多种设备(例如手表和手机)的工作流(如果您的应用需要此类支持)。如需详细了解如何设置用于测试的连接,请访问将手表连接到手机。
注意:如果您没有实体手表,还可以通过 Android Studio 在模拟器上测试并运行您的应用。
更新到最新版本的 Wear OS
为帮助验证您的应用在最新版软件上的行为是否符合预期,请检查您的测试设备是否搭载了设备支持的最新版本的 Wear OS。
如需在测试设备上检查系统更新,请完成以下步骤:
- 将设备连接到 Wi-Fi 网络。
- 开始为设备充电。
- 等待设备的电池电量达到 50% 或更高。
-
在测试设备上,依次前往“设置”>“系统”>“系统更新”。
如果有系统更新,系统会将其下载并安装到您的测试设备上。
安装特定版本的 Wear OS(可选)
如果应用的测试用例依赖于特定版本的 Wear OS,您可以将软件映像刷写到支持 USB 数据连接的手表上。例如,您可以将出厂映像或完整的 OTA 映像刷写到 Google Pixel Watch 3 或 Google Pixel Watch 2 设备上。
在手表上启用开发者选项
在手表上进行调试之前,请先启用开发者选项。您只需执行此操作一次。开发者选项将保持启用状态,直到您将其停用。如需启用开发者选项,请执行以下操作:
- 打开手表的设置。
- 依次点按系统 > 关于 > 版本。
- 点按 Build 号七次。
- 系统会显示一条消息,确认您现在处于开发者模式。
通过 Wi-Fi 调试
在开始之前,在手表上按照上文所述步骤启用开发者选项。
将手表连接到 Wi-Fi 网络
- 打开手表的设置。
- 依次点按连接 > Wi-Fi。
- 选择一个网络并根据需要输入密码。
注意:手表和您的开发机器必须连接到同一网络。并非所有接入点都适用。您可能需要使用防火墙已正确配置为支持 adb
的接入点。
启用 Wi-Fi 调试
- 打开手表的设置。
- 依次点按开发者选项 > 通过 WLAN 调试。
- 片刻后,屏幕会显示手表的 IP 地址,例如
192.168.1.100
。执行下一步时会用到它,因此请记录下来。
将调试程序与手表配对
- 在 Wear OS 设备上,找到系统中的无线调试选项
设置。选择与新设备配对。
- 记下 Wi-Fi 配对码和 IP 地址和端口。
-
在开发机器上的终端窗口中,输入以下内容
命令:
adb pair IP_ADDRESS:PORT
-
出现提示时,输入第 2 步中的 Wi-Fi 配对码。终端将输出配对是否成功。例如:
Enter pairing code: 123456
Successfully paired to 192.168.1.100:5555
配对后,主机会显示在
已配对的设备列表中
。
将调试程序连接到手表
- 将您的手表和开发机器连接到同一网络。
使用手表的 IP 地址和一个端口号,将调试程序连接到手表。例如,如果 IP 地址是 192.168.1.100
且端口号为 5555
,则 adb connect
命令及其响应将如下所示:
adb connect 192.168.1.100:5555
connected to 192.168.1.100:5555
手表现已连接调试程序,您可以随时开始调试。使用 -s
标志向手表发送 adb
命令,并指定手表的 IP 地址和端口号:
adb -s 192.168.1.100:5555 <command>
如果您使用的不是模拟器,并且只连接了一个设备进行调试,则不需要指定地址:
adb <command>
通过蓝牙调试
注意:蓝牙调试仅适用于搭载 Wear OS 2 的 Android 配对手表。
在开始之前,请将手表和手机配对,并在手表上启用开发者选项(如前所述)。在手机上打开设置菜单,然后查找开发者选项,检查手机上是否已启用开发者选项。如有必要,请在手机上启用开发者选项。
在手机上启用 USB 调试
- 打开手机的设置菜单。
- 选择开发者选项并启用 USB 调试。
在手表上启用 adb 或蓝牙调试
- 打开手表的设置菜单。
- 滚动到开发者选项。
- 确认已启用 ADB 调试。
- 启用通过蓝牙调试。
在手机上启用蓝牙调试
- 在手机上,打开 Wear OS 配套应用。
- 滚动到高级设置,然后点按以查看高级设置选项。
- 启用通过蓝牙调试。该选项下会显示以下状态消息:
Host: disconnected
Target: connected
此时,开发机器(主机)并未与手表(目标)通信。您需要完成此关联。
注意:您一次只能在一个设备上进行调试。
如果您配对了多个手表,系统只会在主屏幕上选择的设备上启用蓝牙调试。
将调试程序连接到手表
在这最后一步中,所有东西都会用到:调试程序、手机和手表。
- 使用 USB 线将手机连接到您的开发机器。
- 在调试程序中运行以下两个命令:
adb forward tcp:4444 localabstract:/adb-hub
adb connect 127.0.0.1:4444
注意:您必须使用 IP 地址 127.0.0.1。使用开发机器上的任何可用端口,并在两个命令中使用同一端口。在本例中,端口为 4444。
- 输入 connect 命令后,手表会提示您确认是否允许 adb 调试。
- 在手机上,检查 Wear OS 配套应用中显示的状态是否包含以下内容:
Host: connected
Target: connected
手表现已连接到调试程序,您可以随时开始调试。
使用蓝牙调试手表时,adb
始终使用 IP 地址 127.0.0.1
外加您指定的端口。在本例中,端口为 4444
。所有 adb
命令均使用以下格式:
adb -s 127.0.0.1:4444 <command>
如果您使用的不是模拟器,并且只连接了一个设备进行调试,则不需要指定地址:
adb <command>
使用 Wear OS 的屏幕录制功能
如果在 macOS 上开发,您可以使用 GitHub 项目 Android tool for Mac 在 Wear OS 设备上录制视频。
或者,您也可以按照以下步骤在 Wear OS 设备上录制视频:
- 在手表上录制原始帧:
adb shell screenrecord --time-limit 30 --output-format raw-frames --verbose /sdcard/video.raw
- 将原始文件复制到开发机器:
adb pull /sdcard/video.raw video.raw
- 使用
ffmpeg
将原始文件转换为 MP4:
ffmpeg -f rawvideo -vcodec rawvideo -s 400x400 -pix_fmt rgb24 -r 10 -i video.raw -an -c:v libx264 -pix_fmt yuv420p video.mp4
注意:如需下载和安装说明,请访问 FFmpeg 网站。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Debug a Wear OS app\n\nTo debug your Wear OS app on a physical watch, connect your development machine to the watch using\nWi-Fi or Bluetooth. Alternatively, if your watch has a USB port,\n[connect using USB](/training/wearables/apps/creating#connect-watch-wired).\n\n\nYou can also test workflows that span multiple devices, such as a watch and a\nphone, if your app requires this support. To learn more about how to set up\na connection for testing, visit\n[connect a watch to a\nphone](/training/wearables/get-started/connect-phone).\n\n**Note:** If you don't have a physical watch, you can also\ntest and [run\nyour app on an emulator](/training/wearables/get-started/creating#run-emulator) in Android Studio.\n\nUpdate to the latest version of Wear OS\n---------------------------------------\n\nTo help verify that your app behaves as expected on the latest software,\ncheck that your test device is running the most up-to-date version of Wear OS\nthat your device supports.\n\nTo check for a system update on your test device, complete these steps:\n\n1. Connect the device to a Wi-Fi network.\n2. Start charging the device.\n3. Wait for the device's battery to charge to 50% or higher.\n4. On your test device, navigate to\n **Settings \\\u003e System \\\u003e System updates**.\n\n If a system update is available, it'll be downloaded and installed onto\n your test device.\n\n### Install a specific version of Wear OS (optional)\n\nIf your app's test case depends on a specific version of Wear OS, you can\nflash a software image onto watches that support a USB data connection. For\nexample, you can flash a\n[factory image](https://developers.google.com/android/images-watch)\nor a\n[full OTA image](https://developers.google.com/android/ota-watch)\nonto a Google Pixel Watch 3 or Google Pixel Watch 2 device.\n\nEnable developer options on your watch\n--------------------------------------\n\nBefore you can debug on your watch, enable developer options.\nYou only need to do this one time. Developer options remain enabled until\nyou disable them. To enable developer options, do the following:\n\n1. Open the watch's **Settings**.\n2. Tap **System \\\u003e About \\\u003e Versions**.\n3. Tap the **Build number** item seven times.\n4. A message appears confirming that you are now a developer.\n\nDebug over Wi-Fi\n----------------\n\nBefore you begin, enable developer options on the watch as described previously.\n\n### Connect the watch to a Wi-Fi network\n\n1. Open the watch's **Settings**.\n2. Tap **Connectivity \\\u003e Wi-Fi**.\n3. Choose a network and enter its password if necessary. **Note:**\n The watch and your development machine must be connected to the same network. Not all\n access points are suitable. You may need to use an access point whose firewall is configured\n properly to support `adb`.\n\n### Enable Wi-Fi debugging\n\n1. Open the watch's **Settings**.\n2. Tap **Developer options \\\u003e Debug over Wi-Fi**.\n3. After a moment, the screen displays the watch's IP address, such as `192.168.1.100`. You need this for the next step, so make a note of it.\n\n### Pair the debugger to the watch\n\n1. On your Wear OS device, find the wireless debugging options in system settings. Select **Pair new device**.\n2. Note the **Wi-Fi pairing code** and the **IP address \\& port.**\n3. In a terminal window on your development machine, type the following command: \n\n ```bash\n adb pair IP_ADDRESS:PORT\n ```\n4. When prompted, enter the Wi-Fi pairing code from step 2. The terminal will output whether pairing was successful. As an example: \n\n ```\n Enter pairing code: 123456\n Successfully paired to 192.168.1.100:5555\n ```\n\nAfter pairing, the host computer appears in the list of **Paired devices** on your Wear OS device's **Wireless Debugging** screen.\n\n### Connect the debugger to the watch\n\n1. Connect your watch and development machine to the same network.\n2. Connect the debugger to the watch using the watch's IP address and a port\n number. For example, if the IP address is\n `192.168.1.100` and the port number is `5555`, the\n `adb connect` command and its response look like this:\n\n ```\n adb connect 192.168.1.100:5555\n connected to 192.168.1.100:5555\n ```\n\nThe watch is now connected to the debugger and you are ready to start debugging.\nSend `adb` commands\nto the watch using the `-s` flag, specifying the watch's IP address and\nthe port number: \n\n```\nadb -s 192.168.1.100:5555 \u003ccommand\u003e\n```\n\nIf you are not using the emulator and have only one device connected for debugging, you don't\nneed to specify the address: \n\n```\nadb \u003ccommand\u003e\n```\n\nDebug over Bluetooth\n--------------------\n\n**Note**: Bluetooth debugging works only for Android-paired\nwatches running Wear OS 2.\n\nBefore you\nbegin, pair the watch and phone and enable [developer options](#enable-dev-options) on\nthe watch as described previously. Check that developer options are enabled on the\nphone by opening the phone's\n**Settings** menu and looking for **Developer Options** .\nIf necessary, [enable developer\noptions](/studio/debug/dev-options#enable) on the phone.\n\n### Enable USB debugging on the phone\n\n1. Open the phone's **Settings** menu.\n2. Select **Developer Options** and enable **USB debugging**.\n\n### Enable ADB or Bluetooth debugging on the watch\n\n1. Open the watch's **Settings** menu.\n2. Scroll to **Developer Options**.\n3. Confirm that **ADB debugging** is enabled.\n4. Enable **Debug over Bluetooth**.\n\n### Enable Bluetooth debugging on the phone\n\n1. On the phone, open the Wear OS companion app.\n2. Scroll to **Advanced Settings** and tap to view the **Advanced Settings** options.\n3. Enable **Debugging over Bluetooth** . The following status message appears under the option: \n\n ```\n Host: disconnected\n Target: connected\n ```\n\nAt this point the development machine---the host---is not communicating with\nthe watch---the target. You need to complete the link.\n\n**Note**: You can only debug with one device at a time.\nIf you have multiple watches paired, Bluetooth debugging is only enabled\nwith the device selected on the main screen.\n\n### Connect the debugger to the watch\n\nIn this final step, you use everything: the debugger, the phone, and the watch.\n\n1. Connect the phone to your development machine with a USB cable.\n2. Run these two commands in the debugger: \n\n ```\n adb forward tcp:4444 localabstract:/adb-hub\n adb connect 127.0.0.1:4444\n ```\n\n **Note**: You must use the IP address 127.0.0.1. Use any available port\n on your development machine, and use the same port in both commands. In this example, the\n port is 4444.\n3. After you enter the connect command, the watch asks you to confirm that you are allowing **ADB Debugging**.\n4. On the phone, check the status display in the Wear OS companion app for the following: \n\n ```\n Host: connected\n Target: connected\n ```\n5. The watch is now connected to the debugger, and you're ready to start debugging.\n\nWhen you debug a watch using Bluetooth, `adb` always uses the IP address `127.0.0.1`\nplus the port that you assign. In this example, the port is `4444`. All `adb` commands use the\nfollowing format: \n\n```\nadb -s 127.0.0.1:4444 \u003ccommand\u003e \n```\n\nIf you are not using the emulator and have only one device connected for debugging, you don't\nneed to specify the address: \n\n```\nadb \u003ccommand\u003e\n```\n\nUse screen record for Wear OS\n-----------------------------\n\nIf you develop on macOS, you can use the GitHub project\n[Android tool for Mac](https://github.com/mortenjust/androidtool-mac/blob/master/README.md) to record a video from your Wear OS device.\n\nAlternatively, record a video from your Wear OS device using the following steps:\n\n1. Record raw frames on the watch: \n\n ```\n adb shell screenrecord --time-limit 30 --output-format raw-frames --verbose /sdcard/video.raw\n ```\n2. Copy the raw file to your development machine: \n\n ```\n adb pull /sdcard/video.raw video.raw\n ```\n3. Use `ffmpeg` to convert the raw file to MP4: \n\n ```\n ffmpeg -f rawvideo -vcodec rawvideo -s 400x400 -pix_fmt rgb24 -r 10 -i video.raw -an -c:v libx264 -pix_fmt yuv420p video.mp4\n ```\n\n **Note:**\n Refer to the [FFmpeg](https://www.ffmpeg.org/download.html) website for download and\n installation instructions.\n\n\nRefer to the following related resources:\n\n- [Android Debug Bridge (adb)](/studio/command-line/adb)\n- [Debug your app](/studio/debug)\n- [Design principles](/training/wearables/design/design-principles)\n- [Capture Wear UI screens](/training/wearables/get-started/screenshots)"]]