user924
user924

Reputation: 12145

Wi-Fi Debug (ADB) - There was an error pairing the device

When I first update to new version of studio I tried to use this new WiFi debug feature and it was working at first time (using QR code or manually typing the code) but now it's stuck with "Connecting to device. This takes up to 2 minutes." message for some time and then I get "There was an error pairing the device" message. Before it would take a couple of seconds to connect. My device is Samsung S10 (12 Android)

enter image description here

Update:

Using real MAC for the current Wi-Fi network on Android devices doesn't really solves the issue:

enter image description here

Mb it helps in some cases, but after I tested it for a while it still can't connect from time to time so I have to manually open Wireless Debug screen on a Android device and check ip:port to enter manually adb connect ip:port in Terminal.

IPs of devices never change. I set static for all devices in router's settings. It also doesn't help.

So for now none of these solutions solves the issue for good.

I still have to call the following in Terminal:

adb kill-server
net stop winnat
net start winnat
adb start-server

(net * winnat - For windows)

Then switch Wi-Fi on the device to make it work again.

So I can't accept the answer yet, though some answers may help in some cases (but we need a 100% solution)

Upvotes: 49

Views: 47154

Answers (16)

BArtWell
BArtWell

Reputation: 4044

I have written a script below for quickly connecting using adb pair and adb connect on Mac: https://gist.github.com/bartwell/05cb8f4e2a913229ea652fe1eed956e7

Usage:

./script.sh 192.168.0.101
./script.sh 192.168.0.101 --restart-server
./script.sh -h

Upvotes: 0

Diljeet
Diljeet

Reputation: 1976

Hi i am a ios/android developer and use MacOS for android wifi debugging and it was always problematic.

I almost used all the solutions above like, restart everything, revoke adb authorizations, adb kill-server, sometimes worked, adb connect, adb pair, i have experience so i know how to write commands, i never made mistake still it stopped working.

All solutions and work arounds - for Mac

  1. My solution was to re enable the app Android Studio to access Local Networks - for this goto Settings->Privacy & Security->Local Network - then disable android studio and then re enable it - then restart androd studio, it detected all paired devices
  2. note the "Randomized MAC Address" should be disabled, you should use "Device Mac" if option not available, forget the network on android device and re-add wifi network and change the Randomized MAC Address
  3. ./adb connect and ./adb pair are useless if they will work then the Android studio connect dialog will work too, so not really useful, when android studio connect dialog doesn't work, these commands will also not work, i tried a lot
  4. disable in wifi network connection settings - Limit IP tracking, if necessary

Edit: All steps line wise, first install an app named LocalSend on both mac and android phone (its a free opensource app to transfer data between android/mac)

  1. open local send on both mac and android, then check if the mac is detecting your android phone & vice-versa, if android is not detecting, disable Limit IP tracking in wifi settings, and if only mac is not detecting the android device then disable + re-enable the Local Networks Access as mentioned above. for both LocalSend and Android Studio
  2. check again in local send after restarting it, if it detects the device, then close it goto android studio either restart it or restart adb from troubleshoot device connections or using adb commands
  3. then re-enable wifi debugging after disabling, then click pair device using wifi, and if it displays a loader then device is being connected (if device already paired), else try to pair the device using qr or pairing code.
  4. now if you can see the device in LocalSend app and still not connected in Android Studio after restarting adb, then goto pair device using wifi-> then click pair using pairing code, then in phone wifi debugging click, pair using paring code(even if you have already paired), now if you can see the device in android studio pairing window even if you have already paired the device, then you can either use adb connect ... command or you need to disable USB debugging and then re enable usb debugging and wifi debugging, then it will connect.

These steps i have worked with from a long time in macos 15.2 currently - works all the time 100% Look at the things we do as a developer haha!

Note: Installing LocalSend is not mandatory, its optional, just to check if you device is detected on mac, and once the device is detected by mac, we can use adb connect ... or we follow other solutions like disabling/enabling wifi debugging or in last disabling/enabling USB debugging, in my mac sometimes it doesn't even detect the device in LocalSend or other sharing apps, so other solutions of reseting adb/usbdebugging doesn't work, so first i make sure that the sharing apps detect my device and then follow other solutions related to android instead of wifi connection

Upvotes: 0

Hasanboy Qodirov
Hasanboy Qodirov

Reputation: 21

Try to turn off Developer Options and turn on again. It works like a charm. Happy coding!

Upvotes: 0

Taufiq Rahman
Taufiq Rahman

Reputation: 5704

What worked for me was simply restart the adb server.

adb kill-server

adb start-server

Upvotes: 1

dedy
dedy

Reputation: 99

  • Turn off developer options, then turn them on again.
  • Turn on usb debugging.
  • Turn on wireless debugging.
  • And the problem is solved.

Upvotes: 0

gtxtreme
gtxtreme

Reputation: 3566


EDIT 3: A lot of people have reported that toggling Developer Settings work as well.Also ensure that you're not connected to the VPN, since tunneling is affected
EDIT 2: Take a look at the below answers, the actual reason seems to be that the device is assigned a random IP or a MAC via DHCP, if you can disable that via system settings for your specific custom ROM, then it's even better

EDIT: If you see regular disconnections, click on `Pair Device with Pairing Code`, and then pair your device with the following command
adb pair <ip-addr>:<port> <pairing_code>

I was facing the same issue, what I did was switching to the command line way of connecting with the device. You can do so in the following way

  1. Make sure USB Debugging is enabled on the device you intend to connect with
  2. In your device, go to Developer Settings>Wireless Debugging and you will see something like so

Sample Screenshot

  1. Now carefully look at the IP ADDRESS AND PORT section and type the following in the terminal
  adb connect <ip-addr>:<port>

And your computer will show under paired devices like the above screenshot

Upvotes: 50

Siddy Hacks
Siddy Hacks

Reputation: 2310

I am going to give you a age old solution

  1. Turn off Developer Options
  2. Turn On Developer Options
  3. Turn on USB Debugging
  4. Turn On Wireless Debugging
  5. Try to connect with QR Code
  6. Be Happy when you see that turning this off and on still is a solution to many complex problems

Upvotes: 14

user924
user924

Reputation: 12145

I fixed it by manually assigning IP addresses for my smartphone and PC at settings of the router. Basically avoiding DHCP.

Restarted the router.

Cleared old pairing.

Started pairing again and now it works fine all the time, and no need to repeat pairing process, just enabling "Wireless debugging" from notification panel and in couple of seconds the device will be available in Android Studio

So next time just enable "Wireless debugging" and it's ready

enter image description here

I don't know why there the issue with dynamic IPs

p.s.: though I'm not sure if using the same IP address really fixes it (need to test it for sure), so can't accept any answer for now

Upvotes: 3

thecoolmacdude
thecoolmacdude

Reputation: 2277

I initially got this error as well, but was able to successfully pair successfully after restarting the device.

Upvotes: 0

I had the same problem but I managed to find the solution. You have to follow the following steps:

  1. In your smartphone (Go to Settings->Developer options-> Wireless Debugging->Pair device with pairing code).
  2. Copy the ipaddress & port. For example: 192.168.1.2:42123 and wifi pairing code: 234321.
  3. Open your terminal and go to the following path: cd %LOCALAPPDATA%/Android/sdk/platform-tools
  4. Paste the following command following this order: adb pair (ipaddress & port that you saw when you clicked on "Pair device with pairing code") adb pair 192.168.1.2:42123
  5. Paste the access code to the wifi connection. Enter pairing code: 41107.
  6. Finally, on the same screen go to the option that says IP address and port and you will see the same address but with another port (You can find it in this part of your screen), copy it and write the following command: adb connect 192.168.1.2:41107

If you see a message like this "connected to 192.168.1.2:41107", you did it you will be able to connect your phone with android studio without any problem.

Upvotes: 10

Ahmed Saad
Ahmed Saad

Reputation: 175

This really helped me

Using Terminal Tool

Pairing: `

  1. enable wireless debugging
  2. click on Pair device with pairing code
  3. in terminal type: adb pair {ip_address}:{port} {pairing_code}
  4. you will see your pc name below Paired devices `

Connecting: `

  1. Note ip and port found above Pair device with QR code [VERY IMPORTANT]
  2. in terminal type: adb connect {ip_address}:{port}
  3. you will see Currently connected below your pc name ,congrats :)

Note: next time you can use Connecting step if your pc already paired

Upvotes: 5

enable the USB debugging option in your mobile device and then retry connecting through wireless option, It will work

In my case It worked

Upvotes: 0

Ronald Ara&#250;jo
Ronald Ara&#250;jo

Reputation: 1479

Important reminder and this is what solved my problem.

Devices must be on the same network.

Upvotes: -2

Hisham Hijjawi
Hisham Hijjawi

Reputation: 2415

Note that for me pairing wouldn't work while I was on my VPN. After I paired while off the VPN, I could adb connect ipaddress:port and it worked.

Upvotes: 3

Shriram Panchal
Shriram Panchal

Reputation: 2086

This worked for me:

  • Tools --> Troubleshoot Device Connections
  • Press Next --> Next
  • Click 'Restart ADB server'
  • Freshly turn ON Wireless Debugging on device and wait for few seconds.

Upvotes: 2

Mike J
Mike J

Reputation: 806

I was able to resolve the issue from within Wi-Fi settings by disabling the Randomized MAC Address feature under Privacy. Using my device's actual MAC address fixes the issue.

Android Wi-Fi Settings

Upvotes: 66

Related Questions