Android Debug Bridge (ADB) Hubungkan ke Perangkat melalui USB, WiFi

โšก Ringkasan Cerdas

Android Debug Bridge connects a workstation to an emulator or a physical handset, opening a shell, installing builds and exposing the device to automation tools over either a USB cable or a wireless link.

  • ???? Tiga bagian: ADB is a client, a background server on TCP port 5037 and a daemon running on the device.
  • โ˜‘๏ธ First requirement: USB debugging must be switched on under Developer Options before any device appears.
  • โœ… Verify the link: adb devices lists every attached emulator and handset with its serial number.
  • ๐Ÿงช Target one device: adb -s <serial> sends a command to a single device when several are connected.
  • ๏ธ Wireless option: adb tcpip 5555 followed by adb connect moves an existing session onto Wi-Fi.
  • ๐Ÿ“Š Modern devices: Android 11 and higher pair over Wi-Fi with adb pair, so no cable is needed at all.

Android Debug Bridge connecting a device over USB and Wi-Fi

Apa itu Android Jembatan Debug (ADB)?

Android Debug Bridge (ADB) is a command-line tool that lets you communicate with a device. It bridges an emulator instance (Android device) and the background daemon process (server), so you can install builds, debug a device and run commands through a Unix shell.

Using a real device for mobile automation pengujian has always been a challenge. Android offers solutions to connect one over USB (Universal Serial Bus) โ€” namely Android Debug Bridge.

USB debugging dan Konfigurasi ADB

Appium can execute tests on real devices, but the following pre-requisites must be set up first.

  • USB debugging harus diaktifkan
  • Konfigurasi ADB
  • Pengaturan kemampuan yang diinginkan sesuai perubahan perangkat keras.

We will cover both an emulator and a real device. The emulator steps come first.

Cara Menghubungkan ke Emulator

Pre-requisite: the SDK (Software Development Kit) should be installed on the machine. ADB in Android dikemas dengan Google'S Android SDK.

Langkah-langkah untuk mengaktifkan ADB dari SDK Manager.

Langkah 1) Open Android folder SDK

Langkah 2) Double klik pada Manajer SDK

Langkah 3) Dari daftar semua paket pilih Alat dan tandai kotak centang untuk

  • Android Alat SDK dan
  • Android Alat Platform SDK.

The SDK Manager package list with both entries ticked is shown below.

Android SDK Manager package list with Android SDK Tools and Platform-tools selected

โš ๏ธ Catatan versi: the standalone SDK Manager above was deprecated in SDK Tools 25.2.3 and its launcher removed in 25.3.0. Open the same package list from Android Studio (Tools > SDK Manager) or the sdkmanager CLI. The package is still Android SDK Platform-tools, yang mengandung adb.

Bagaimana Menghubungkan Android Perangkat dengan ADB (Android Jembatan Debug)

Langkah 1) Enable USB Debugging on your device

Enable the USB debugging option from โ€˜Developer Optionโ€™ on the Android phone, then connect the device to the computer with a USB cable, as shown here.

USB debugging switch enabled inside Developer Options on an Android telepon

Langkah 2) Pergi ke Android folder SDK

Open the folder where the Android SDK files were saved, โ€˜Android SDK >> Platform-toolsโ€™ โ€” for example C:\android-sdk\platform-tools, ditunjukkan di bawah ini.

Windows Explorer open at the platform-tools folder inside the Android SDK

Langkah 3) Open the Command window

Inside the folder, hold Shift and use the right-click menu >> select โ€˜Open command window hereโ€™, shown below. You can also reach the folder path from the Run command.

Shift plus right-click context menu showing Open command window here

The command prompt then opens already pointed at the platform-tools folder.

Command prompt window opened directly in the platform-tools directory

Langkah 4) Connect an external Android alat

Connect an external Android device (mobile phone) with its USB cable. Then, in the command prompt above, type:

'adb devices' & press Enter

It will display a list of all the connected devices, as shown below.

Command prompt output of adb devices listing an attached device serial

First check whether the ADB server is running as a background process: type โ€˜adbโ€™ in the same command prompt and press enter. It should list the adb processes running.

When the server starts it binds local TCP port 5037. All ADB clients use port 5037 to reach the server, which then scans ports to find every connected emulator or device instance.

The ADB daemon runs on an odd-numbered port and the matching emulator console takes the even-numbered port beside it. Android'S ADB documentation puts the scanned range at odd ports 5555 to 5585, covering the first 16 emulators.

If a single device is connected, the server finds and connects to it automatically. With several devices or emulators running, you must name the target on the command line. The instance on odd port 5557 has its console on even port 5556 โ€” one odd and one even port each.

emulator 1: console 5556
emulator 1: adb 5557
emulator 2: console 5554
emulator 2: adb 5555

Command to detect all connected devices:

<$ adb devices>
emulator-5554 device
emulator-5556 device
emulator-5558 device

Command detecting a single device from multiple connected devices:

<$ adb -s emulator-5554 install Guru99.apk>

It targets the adb connection for device 5554 and installs the application โ€” this is how you address a single ADB instance from the command line.

Syntax used to access ADB instances from the command line:
adb -d โ€” An adb command when a single USB device is connected
adb -e โ€” An adb command when only a single emulator is running
adb devices โ€” This will print the list of emulators / devices attached.
adb version โ€” List the adb version number.
adb help โ€” Print the list of supported commands.

How to Configure ADB for Wi-Fi Support

ADB can also be configured over Wi-Fi, which frees the handset from the cable during a long Appium menjalankan.

Prasyarat

  • Keduanya Android device and the host computer should be connected to the same wireless network, and
  • the device Bluetooth option should be disabled.

Langkah-langkah untuk menghubungkan:

  1. Connect the device using a USB cable to the host computer. Confirm USB debugging is enabled on the device.
  2. Set the target device to listen for a TCP/IP connection on port 5555.
    $ adb tcpip 5555

The command prompt confirms the switch to TCP/IP mode, as shown below.

Command prompt showing the adb tcpip 5555 command restarting the daemon in TCP mode

  1. Now disconnect the USB cable from the device.
  2. On the device, find the IP address under Settings >> Wi-Fi Setting >> Advanced >> IP Address. Connect to it, then confirm the session.
    $ adb connect 148.100.1.17:5555
    $ adb devices
    List of devices attached
    148.100.1.17:5555 device

The configuration is now complete and โ€˜adbโ€™ is working over the wireless network.

โš ๏ธ Catatan versi: the cable-first sequence above remains the only route on Android 10 dan lebih rendah. Android 11 (API 30) and higher add Wireless debugging: enable it in Developer Options, choose Pasangkan menggunakan kode pasangan, lalu lari adb pair ipaddr:port and enter the code. No cable needed.

NOTE: if a connection error occurs, kill the adb host connection below, then reconnect from step one.

$ adb kill-server

If you are looking for an emulator, see this daftar yang terbaik Android emulator untuk Windows.

Pertanyaan Umum Demo Slot

The RSA key prompt on the handset was never accepted. Unlock the screen, reconnect the cable and tap Allow USB debugging. If no prompt appears, revoke USB debugging authorisations in Developer Options and try again.

Machine learning groups near-identical stack traces from logcat, ranks crashes by affected sessions and flags the first commit likely to have caused a regression, so a tester reads a handful of clusters instead of thousands of lines.

Copilot completes routine loops over adb devices, install and pull commands from a comment. Verify every generated command on one handset first, because a wrong flag can wipe application data without a confirmation prompt.

Use adb install with a path to the APK, add the -r flag to reinstall over an existing build, and use adb uninstall with the package name to remove it. Add -s to target one device.

Confirm USB debugging is on, try a data-capable cable rather than a charge-only one, install the manufacturer USB driver on Windows, and run adb kill-server followed by adb devices to restart the daemon.

adb tcpip switches an existing USB session to a network port and works on every version. adb pair uses the Wireless debugging screen added in Android 11 and needs no cable at any point.

No. The adb binary ships inside the Android SDK Platform-tools package, which can be downloaded on its own. Add that folder to your PATH and the command works from any directory.

Run adb logcat to stream the system log, and adb logcat > log.txt to save it. Add adb bugreport for a full diagnostic archive when you need to attach evidence to a defect.

Ringkaslah postingan ini dengan: