Langsung ke konten

Paling sering dikunjungi

Terakhir dikunjungi

navigation

Debugging a Wear OS App

To debug your Wear OS app, you can connect your development machine to a watch via Wi-Fi or Bluetooth, as described on this page. If your watch has a USB port, you can connect via USB.

Refer to the following related resources:

Enable Developer Options on your watch

Before you can debug on your watch you must enable developer options. You only need to do this one time. Developer options remain enabled until you disable them.

  1. Open the watch's Settings.
  2. Tap System > About.
  3. Scroll to Build number and tap the build number seven times.
  4. A dialog will appear confirming that you are now a developer.

Debugging over Wi-Fi

Before you begin be sure you've enabled developer options on the watch.

Connect the watch to a Wi-Fi network

  1. Open the watch's Settings.
  2. Tap Connectivity > Wi-Fi.
  3. Choose a network and enter its password if necessary.

    Note: The watch and your development machine must be connected to the same network. Beware that not all access points are suitable. You may need to use an access point whose firewall is configured properly to support adb.

Enable Wi-Fi debugging

  1. Open the watch's Settings.
  2. Tap Developer options > Debug over Wi-Fi.
  3. After a moment the screen will display the watch's IP address (for example 192.168.1.100). You'll need this for the next step so make a note of it.

Connect the debugger to the watch

  1. Be sure your watch and development machine are connected to the same network.
  2. Connect the debugger to the watch using the watch's IP address. For example, if the IP address is 192.168.1.100, the adb connect command and its response will look like this (a port number, 5555 is added to the address):

    adb connect 192.168.1.100
    connected to 192.168.1.100:5555
    

The watch is now connected to the debugger and you're ready to start debugging. Send adb commands to the watch using the -s flag and specify the watch's IP address, including the port number:

adb -s 192.168.1.100:5555 <command>

If you are not using the emulator and have only one device connected for debugging, you don't need to specify the address at all:

adb <command>

Debugging over Bluetooth

Bluetooth debugging only works for Android-paired watches. Before you begin, be sure the watch and phone are paired and you've enabled developer options on the watch. You should also be sure that developer options is also enabled on the phone. To check, open the phone's Settings menu, select About phone and click the build number seven times.

Enable USB debugging on the phone

  1. Open the phone's Settings menu.
  2. Select Developer Options and enable USB debugging.

Enable ADB/Bluetooth debugging on the watch

  1. Open the watch's Settings menu.
  2. Scroll to Developer Options.
  3. Confirm that ADB debugging is enabled.
  4. Enable Debug over Bluetooth.

Enable Bluetooth debugging on the phone

  1. On the phone, open the Wear companion app.
  2. Scroll down to Advanced Settings and tap to view the Advanced Settings options.
  3. Enable Debugging over Bluetooth. A status message appears under the option. It looks like this:
    Host: disconnected
    Target: connected
    

At this point the development machine (the host) is not communicating with with the watch (the target). You need to complete the link.

Note: You can only debug with one device at a time. If you have multiple watches paired, Bluetooth debugging will only be enabled with the device selected on the main screen.

Connect the debugger to the watch

In this final step, you'll use everything: the debugger, the phone, and the watch.

  1. Connect the phone to your development machine with a USB cable.
  2. Run these two commands in the debugger:
    adb forward tcp:4444 localabstract:/adb-hub
    adb connect 127.0.0.1:4444
    

    Note: You must use the IP address 127.0.0.1. You can use any available port on your development machine. Be sure you use the same port in both commands. (In this example the port is 4444.)

  3. After you type the connect command, look at the watch. It will ask you to confirm that you are allowing ADB Debugging.
  4. Go back to the phone and check the status display in the Wear companion app. It should look like this:
    Host: connected
    Target: connected
    
  5. The watch is now connected to the debugger and you're ready to start debugging.

When you debug a watch using Bluetooth, adb always uses the IP address 127.0.0.1 plus the port that you assigned. Therefore, all adb commands use this format (continuing the example, the port is 4444):

adb -s 127.0.0.1:4444 <command> 

If you are not using the emulator and have only one device connected for debugging, you don't need to specify the address at all:

adb <command>

Using screenrecord for Wear

If you develop on macOS®, you can use a GitHub project, Android tool for Mac, to record a video from your Wear device.

Alternatively, you can record a video from your Wear device using the following steps:

  1. Record raw frames on the watch:
    adb shell screenrecord --time-limit 30 --output-format raw-frames --verbose /sdcard/video.raw
  2. Copy the raw file to your development machine:
    adb pull /sdcard/video.raw video.raw
  3. Use ffmpeg to convert the raw file to 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

    Note: Refer to the FFmpeg website for download and installation instructions.

Situs ini menggunakan cookies untuk menyimpan preferensi Anda tentang bahasa di situs tertentu dan opsi tampilan.

Dapatkan berita dan tips terbaru dari developer Android yang akan membantu Anda mencapai kesuksesan di Google Play.

* Wajib Diisi

Hore!

Ikuti Google Developers di WeChat

Buka situs ini dalam bahasa ?

Anda meminta halaman dalam bahasa , namun preferensi bahasa untuk situs ini adalah .

Ingin mengubah preferensi bahasa dan mengakses situs ini dalam bahasa ? Jika nanti Anda ingin mengubah preferensi bahasa, gunakan menu bahasa di bagian bawah setiap halaman.

Kelas ini memerlukan tingkat API atau yang lebih tinggi

Dokumen ini tersembunyi karena level API yang Anda pilih untuk dokumentasi ini adalah . Anda dapat mengubah level API dokumentasi dengan pemilih di atas menu navigasi sebelah kiri.

Untuk informasi lebih lanjut tentang menentukan level API yang diperlukan aplikasi Anda, baca Mendukung Versi Platform Yang Berbeda.

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)