androidflutterusb-debugging

Flutter does not prompt the device for an authorization dialog


adb connects to my device (Xiaomi Redmi 4, MIUI 11.0.2, Android 7.1.2) just fine via USB as well as via WiFi. However, I've had no success trying to connect flutter. Flutter does detect my device when I connect via USB but doesn't prompt for an Authorization dialog:

$ flutter doctor

Doctor summary (to see all details, run flutter doctor -v):                                                                             
[✓] Flutter (Channel beta, v1.14.6, on Linux, locale en_US.UTF-8)                                                                       
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Android Studio (version 3.6)                                                                                                        
[!] Connected device                                                                                                                                                                                        
! Doctor found issues in 1 category.

$ flutter devices                                                                                                                         
No devices detected.                                                                                                                    

Run 'flutter emulators' to list and start any available device emulators.                                                               

Or, if you expected your device to be detected, please run "flutter doctor" to diagnose potential issues, or visit                      
https://flutter.dev/setup/ for troubleshooting tips.                                                                                    

• Device 9fd66a407d14 is not authorized.                                                                                                
You might need to check your device for an authorization dialog. 

I've tried

but flutter still says that my device is not authorized.

Is there a solution for this?


Solution

  • I had another issue with adb in which when I connect to my device via USB or WiFi, it would prompt me for authorization even after I check "Always allow from this computer" (This was the case for more than a year and I never really knew why)

    Turns out that was because I had ~/.android/adbkey owned by the root user. So as a normal user, adb won't be able to write to that file which means that it wouldn't be able to remember devices. I solved that with the steps in this answer:

    As described in this issue, this can happen if you run adb for the first time as root. It creates a key file on your computer owned by the root user, so your normal user account can't read or overwrite it.

    To check if this is the case:

    $ ls -l ~/.android/adbkey
    -rw------- 1 root root 1708 Nov 13  2012 .android/adbkey
                 ^ notice root here
    

    To fix it:

    $ sudo chown $USER: ~/.android/adbkey
    $ ls -l ~/.android/adbkey
    $ -rw------- 1 thomas thomas 1708 Nov 13  2012 /home/thomas/.android/adbkey
                   ^ now shows your username and primary group
    

    Finally, restart the adb server:

    $ adb kill-server
    $ adb start-server
    

    Once I solved that, Flutter worked perfectly!