flutter run: No connected devices

2020-01-26 04:19发布

问题:

I am trying to create a sample application with flutter (fresh installation) android studio is also installed (fresh installation)

Here is the output of flutter run

flutter run  
No connected devices.

the output of flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.1.5, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.0)
[!] VS Code (version 1.20.1)
[!] Connected devices
! No devices available

! Doctor found issues in 2 categories.

Is there a solution to this problem?

回答1:

Flutter supports both iOS and Android device/simulators.

In terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.

Here is a reference document, How you can setup Device/Simulator to run your application.

For, Android (on mac system)

Set up your Android device

To prepare to run and test your Flutter app on an Android device, you’ll need an Android device running Android 4.1 (API level 16) or higher.

  1. Enable Developer options and USB debugging on your device. Detailed instructions are available in the Android documentation.
  2. Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
  3. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device.
  4. Start your app by running flutter run.

By default, Flutter uses the version of the Android SDK where your adb tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.

Set up the Android emulator

To prepare to run and test your Flutter app on the Android emulator, follow these steps:

  1. Enable VM acceleration on your machine.
  2. Launch Android Studio>Tools>Android>AVD Manager and select Create Virtual Device.
  3. Choose a device definition and select Next.
  4. Select one or more system images for the Android versions you want to emulate, and select Next. An x86 or x86_64 image is recommended.
  5. Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
  6. Verify the AVD configuration is correct, and select Finish.

    For details on the above steps, see Managing AVDs.

  7. In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.

  8. Start your app by running flutter run. The connected device name is Android SDK built for , where platform is the chip family, such as x86.

-

  • Here is another document, if you're using (Microsoft) Windows System: Get Started: Install on Windows

Open & Connect Device using Android Studio:

Here is an easier way to open and connect simulators/devices.

Android Studio shows a list of emulators/simulators (installed in your system) or devices (connected to your system). Just select a device, you want to open, from a list, and run project.



回答2:

  • Device Not Found (When setup Flutter in android studio)
  • Project structure -> select latest ANDROID SDK in Project SDK


回答3:

I solved the AVD problem with the flutter using the Flutter console.

Step 1:

C: \ Users \ valer> flutter emulators
6 available emulators:

3.2_QVGA_ADP2_API_22 _-_ Lollipop • 3.2in QVGA (ADP2) • Generic • 3.2 QVGA (ADP2) API 22 - Lollipop
Android_ARMv7a
Android_Accelerated_x86
Nexus S API Google Nexus S API 23
Nexus_S_API_25_1080x1920_Nougart_7.1.1_ • pixel • Google • Nexus S API 25 1080x1920 (Nougart 7.1.1)
Pixel_API_28 • pixel • Google • Pixel API 28

To run an emulator, run flutter emulators --launch <emulator id>.

Step 2:

C: \ Users \ valer> flutter emulators --launch Pixel_API_28


回答4:

This was my solution. Hope my confusion can help someone else too:

My "Developer Options" was ON,

but the "USB Debbugging" was OFF.

So I turned ON the USB Debbugging and the problem was solved.



回答5:

None of the suggestions worked, until I ran

flutter config --android-sdk ANDROID_SDK_PATH


回答6:

In my case

File>Project Structure

select latest sdk



回答7:

I ran mine with Genymotion, probably the best for Flutter.

Setting up is less painful and

Make sure setting ADB under

--YOUR ANDROID SDK PATH --

Mine is C:\Users\user\AppData\Local\Android\Sdk



回答8:

I encounter the same problem as you did. It turns out that your device is not connected with your computer.

Note:

  • If you are using XCode, if both your computer and the device are using the same WIFI, you don't have to connect the device with the computer.
  • For Android, or iOS running under terminal command, if you are using command line to run this, you have to make sure they are connected via cables. Sharing the same WIFI does not work. Make sure your device is really connected.
  • Make sure you allowed USB Debugging on your android device.

If this still does not work, try to fire below command, where you can get richer info and details:

flutter run --verbose


回答9:

What I needed to do:

flutter emulators

It will list all available emulators. For iOS you will need to open simulator first.

flutter emulators --launch EMULATOR NAME

This will launch the emulator

And to build it

flutter run -d "EMULATOR ID"


回答10:

For window user,

Set environment variable of Flutter SDK(...\flutter_windows_v0.2.8-beta.zip\flutter\bin)

No device connect

For more information, you can check here http://www.developerlibs.com/2018/05/flutter-introduction-and-setup.html

Here is the info from the mentioned page: Add Flutter to Windows Environment variable Path

  1. Navigate in to Flutter SDK folder.
  2. Go inside to bin folder and copy the directory path (in your case C:\Flutter\bin)
  3. Go to “Control Panel > User Accounts > User Accounts > Change my environment variables”
  4. Under “User variables” select path variable and click edit.
  5. Put C:\Flutter\bin and apply.

Same as Flutter Environment, we have to set the Android SDK path if it is on custom location.

  1. Navigate into the Android SDK folder.
  2. Copy the directory path (in your case ..AndroidStudioSDK\sdk)
  3. Go to “Control Panel > User Accounts > User Accounts > Change my environment variables”
  4. Under “User variables” select path variable and click edit.
  5. Put ..AndroidStudioSDK\sdk with ANDROID_HOME and apply.

Tips:

If you facing the following issue,

1.[✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from https://developer.android.com/studio/index.html On the first launch, it will assist you in installing the Android SDK components. (or visit https://flutter.io/setup/#android-setup for detailed instructions).

If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location.

You can resolve it with the following command.

flutter config --android-sdk <android-sdk-location> OR flutter config --android-sdk "android-sdk-location"

  1. Error: Unknown argument --licenses

You can resolve it with Following Command.

flutter -v doctor --android-licenses

Now, Pick the emulator you want to use and click the green arrow to run the project. So, here default screen that is already designed.



回答11:

Sometimes you have everything perfect but the device is no longer authorized on ADB. In such cases you have ADB but It will not show you in connected devices.

Steps to Fix this issue

1. Check if authorized: Open terminal/cmd/PowerShell and write adb devices it will show you all connected devices to PC.

<ANDROID_SDK_HOME>\platform-tools>adb devices
List of devices attached
4df798d76f98cf6d        unauthorized

2. Revoke USB Debugging on phone

If the device is shown as unauthorized, go to the developer options on the phone and click "Revoke USB debugging authorization" (tested with JellyBean & Samsung GalaxyIII).

3. Restart ADB Server:

adb kill-server
adb start-server

4. Reconnect Device and run following command again : adb devices

Now it should display authorized.

5. Ready to go.

Now, open you editor Android Studio/Visual Studio Code and check if your device is showing in connected devices or not.

You can simply check that with flutter doctor command.



回答12:

There should be at least one device/Simulator connected to run Flutter applications.

Also make sure the USB debugging is enabled in developer settings.



回答13:

If you have

  • Downloaded the flutter SDK
  • Connected your mobile device and enabled the developer option on the mobile and allowed USB debugging.

And still you are getting "No device connected" then i think you should install ADB driver. It worked for me!! Click here to download



回答14:

I am facing the same issue with Flutter. But I found another way to work i.e.

  1. First run Android Emulator
  2. Then go to your Flutter Console
  3. Run the command flutter doctor & check whether your emulator is showing under connected devices tag e.g. flutter doctor command success output

  4. Now move to your Flutter project path via Flutter console e.g. for me it is D:\FlutterWorkspace\flutter_demo

  5. Then run flutter run command. e.g. flutter run Wait for few moments you will see your app running into Android Emulator. App is running



回答15:

One option that I haven't see mentioned so far is that (for my setup) the Developer Option 'Select USB Configuration' must be set to MTP (Media Transfer Protocol).



回答16:

I am using Linux so here are the step can help. First open studio with root permission, (window : Right-click the program icon > Choose Run As Administrator, linux : sudo ./studio.sh in terminal)

Create emulator with Hardware - GLES 2.0 in hardware acceleration as mentioned here. Open terminal in android studio (Alt+F12)

Run command flutter devices and see the list devices

root@abc-OptiPlex-3050:~/flutter_workspace/my_app/my_app# flutter devices
   Woah! You appear to be trying to run flutter as root.
   We strongly recommend running the flutter tool without superuser privileges.

1 connected device:

Android SDK built for x86 • emulator-5554 • android-x86 • 
Android 8.1.0 (API 27)(emulator)

Finally run from terminal flutter run

root@abc-OptiPlex-3050:~/flutter_workspace/my_app/my_app# flutter run
   Woah! You appear to be trying to run flutter as root.
   We strongly recommend running the flutter tool without superuser privileges.


Using hardware rendering with device Android SDK built for x86. 
If you get graphics artifacts, consider enabling software rendering 
with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                       0.7s
Resolving dependencies...                                    1.2s
Running 'gradlew assembleDebug'...                           1.5s
Built build/app/outputs/apk/debug/app-debug.apk.
I/FlutterActivityDelegate(25096): onResume setting current activity to this
Syncing files to device Android SDK built for x86...             
D/        (25096): HostConnection::get() New Host Connection established 
0xe8487780, tid 25116
D/EGL_emulation(25096): eglMakeCurrent: 0xe5b3d8a0: ver 2 0 (tinfo 0xe84832f0)