23

I'm trying to debug with Android R in Pixel emulated devices w/ PlayServices but the "Allow USB Debugging" dialog instantly close right after showing, so I can't click in "Allow" to AS connect to the AVD. I went to Developer options in Android to switch off and on again the USB debugging, but again the dialog close imediatelly right after showing. I tried kill/star ADB and unistalling all AS/user configs/etc and reinstalling again but didn't solve. Anyone has a clue?

Maurício Lima
  • 504
  • 6
  • 20

9 Answers9

9

Seems like this issue is related to your emulator's API version, after some testing I found that Pixel 4 API 30 have your problem, while others don't.

Versions

Another odd thing about the box is that it will ask you again for permission when you start a new session, even though I clicked the "always allow this device" button.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Ng Lok Chun
  • 199
  • 2
  • 10
7

Wipe data and it will pop up and stay. Check the "always allow debugging on this device" box and you should be good to go.

MandelMech
  • 467
  • 4
  • 6
5

Try remove files adbkey and adbkey.pub in:

  • ~/.android/adbkey/ on Linux
  • %UserProfile%\.android on Windows
  • %ANDROID_SDK_HOME%\.android on Windows, if set
adb kill-server
adb devices

Restart the emulator after wiping its data. Then the permission for "USB Debugging" should be given and it should show up as debuggable device.

The problem should only appear with google_apis_playstore devices, see here. Reason I think is, that the key files are only copied by adb, if no other keys already exist on the emulator. So may deleting the files on the emulator may also work.

Viktor Brešan
  • 5,293
  • 5
  • 33
  • 36
User Rebo
  • 3,056
  • 25
  • 30
  • It didn't help in my case. Dialog is still disappearing before I have a chance to click on it. – Viktor Brešan Apr 24 '22 at 05:42
  • @ViktorBrešan did you change the `ANDROID_SDK_HOME` or `ANDROID_PREFS_ROOT` variable? Make sure any old keys are deleted in any possible `.android` directory. If so, there shouldn't come up a dialog at all, the keys are then copied automatically to your device and you should be able to debug without confirming :) – User Rebo Apr 24 '22 at 13:54
  • 1
    It wasn't problem with folders, I have slightly 'corrected' your answer. – Viktor Brešan Apr 25 '22 at 09:00
4
  1. get your public key from ~/.android/adbkey.pub
  2. append it to /data/misc/adb/adb_keys of emulator (create it if not exist)
  3. restart emulator

then you should connect directly.

ref: How to solve ADB device unauthorized in Android ADB host device?

user2767141
  • 134
  • 5
  • 1
    Unfortunately nothing worked, not even uninstalling Android Studio, the only way to work is to select a non-PlayServices from the AVD list. – Maurício Lima Apr 20 '21 at 12:57
  • i experience the same as @MaurícioLima . also, how would you put the key on the device if you cannot connect to it..? – mx1up Apr 27 '21 at 15:58
2

This problem occurs with Pixel emulators on API level 30, so choosing 31 instead will solve the issue.

1

I had the same issue. I tried to click "Allow" in time, but it was too fast on my PC. However, I noticed that after a cold boot this popup pops and doesn't hide for some time (may be due to load lag), so I managed to click it this way.

If someone still has this problem and the goal is to upload some file or apk, better upload it to google drive and download it by link in the emulator.

UnholyRaven
  • 368
  • 3
  • 9
  • 2
    Actually this is the only way I managed to run the apk, copying and installing it, the AVD doesn't connect to the Android Studio and after 300 seconds give a message that waited and wasn't able to connect. – Maurício Lima Apr 27 '21 at 14:41
1

I solved this problem by following steps:

  1. Wipe emulator data
  2. Start emulator again

Above steps resulted in no dialog at all, weird, then I looked at the Android Studio, the emulator was already connected.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Muhammad Faizan
  • 1,891
  • 2
  • 18
  • 37
0

After some experiments I found that x86 apis were showing this error so simply switching to x86_64 apis solved the problem :

enter image description here

PRANAV SINGH
  • 1,000
  • 11
  • 17
0

In my case, it was because I had enabled an accessibility app. At least, after trying various things (turning on/off developer mode, USB debugging, etc.;, rebooting and so on), I disabled that accessibility service, and voila, the "Allow USB debugging" was back to normal!

auspicious99
  • 3,902
  • 1
  • 44
  • 58