flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.45k stars 27.59k forks source link

Flutter generates an error when running on windows desktop #157437

Open Junkmer opened 1 month ago

Junkmer commented 1 month ago

Steps to reproduce

Now here's the question

I have downloaded and configured the flutter windows desktop environment, running flutter doctor is also normal, creating a new project after selecting the desktop will also work, but when I add any third party plugins in pubspec.yaml, running the following error, How should I solve this problem, or how to troubleshoot it


Flutter 3.22.3 • channel [user-branch] • unknown source
Framework • revision b0850beeb2 (3 months ago) • 2024-07-16 21:43:41 -0700
Engine • revision 235db911ba
Tools • Dart 3.4.4 • DevTools 2.34.3

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.22.3, on Microsoft Windows [版本 10.0.22631.4169], locale zh-CN)
    ! Flutter version 3.22.3 on channel [user-branch] at D:\Junker\Flutter\flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not the same as FLUTTER_GIT_URL
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.11.5)
[√] Android Studio (version 2024.1)
[√] Connected device (3 available)
[√] Network resources

Actual results

image

image

Logs

Logs ```console ```

Flutter Doctor output

Doctor output ```console ```
darshankawar commented 4 weeks ago

@Junkmer Looking at the error you are getting, it may be related to your local pub cache and not in the plugin itself. Looks like damaged pub cache, where package versions are missing files in your cache. Try running flutter pub cache repair to see if it helps or not.

Junkmer commented 4 weeks ago

Ok, I will try to run it later and check it. Thank you very much

Junkmer commented 4 weeks ago

I tried it according to your suggestion, but found it was not successful, the same error was still reported, and there would be an error when adding any third-party library image


PS D:\xxxx\FlutterProjects\self-project\test-flutter-project> flutter clean
Deleting build...                                                    8ms
Deleting .dart_tool...                                               1ms
Deleting Generated.xcconfig...                                       0ms
Deleting flutter_export_environment.sh...                            0ms
Deleting ephemeral...                                                0ms
Deleting ephemeral...                                                0ms
Deleting ephemeral...                                                0ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         0ms
PS D:\xxxx\FlutterProjects\self-project\test-flutter-project> flutter pub cache repair
Reinstalled 660 packages.
PS D:\xxxx\FlutterProjects\self-project\test-flutter-project> flutter pub get
Resolving dependencies... 
Downloading packages... 
  async 2.11.0 (2.12.0 available)
  boolean_selector 2.1.1 (2.1.2 available)
  characters 1.3.0 (1.3.1 available)
  collection 1.19.0 (1.19.1 available)
  fake_async 1.3.1 (1.3.2 available)
  flutter_lints 3.0.2 (5.0.0 available)
  js 0.6.7 (0.7.1 available)
  leak_tracker 10.0.5 (10.0.8 available)
  leak_tracker_flutter_testing 3.0.5 (3.0.9 available)
  lints 3.0.0 (5.1.0 available)
  matcher 0.12.16+1 (0.12.17 available)
  material_color_utilities 0.11.1 (0.12.0 available)
  meta 1.15.0 (1.16.0 available)
  path 1.9.0 (1.9.1 available)
  path_provider_android 2.2.10 (2.2.12 available)
  stack_trace 1.11.1 (1.12.0 available)
  string_scanner 1.3.0 (1.4.0 available)
  vm_service 14.2.4 (14.3.1 available)
Got dependencies!
18 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
PS D:\xxxx\FlutterProjects\self-project\test-flutter-project> flutter run -d windows
Launching lib\main.dart on Windows in debug mode...
CMake Error at flutter/generated_plugins.cmake:15 (add_subdirectory):
  add_subdirectory given source
  "flutter/ephemeral/.plugin_symlinks/tencent_cloud_chat_sdk/windows" which
  is not an existing directory.
Call Stack (most recent call first):
  CMakeLists.txt:59 (include)

Building Windows application...                                     4.0s
Error: Unable to generate build files
darshankawar commented 4 weeks ago

@Junkmer Is it only occuring while trying to add the said third party package or any third party package results in same error ?

Junkmer commented 4 weeks ago

That's right. Just add any plugin and you'll get the same error.

Added: 1, Create Flutter project, do not add any third-party libraries, select windows(desktop) can run successfully 2, add any third-party library, as long as you do not select "window(desktop)" can run successfully

I wonder if there is something wrong with my cmake, but I am running the im Android project with the cmake configuration as normal

This problem has been bothering me for a few days, I tried to upgrade the windows system, upgrade the Flutter version, upgrade the cmake version and couldn't solve it

Junkmer commented 4 weeks ago

If you have any points that you might suspect, just bring them up, I try as much as I can, I look up similar anomalies online, and there is no solution I want

https://github.com/flutter/flutter/issues/141514

This is the only one similar to mine, I have tried it, neither Powershell nor cmd will work

Also run vs code, same error

darshankawar commented 4 weeks ago

Currently on an unknown channel. Run flutter channel to switch to an official channel.

Can you switch to official channel as suggested and try again to check if it still persist ?

Junkmer commented 3 weeks ago

Still no

image

Processor 12th Gen Intel(R) Core(TM) i5-12400F 2.50GHz Machine with RAM 16.0GB (15.8GB available) System Type 64-bit operating system based on x64 processor Pen and Touch There is no pen or touch input available for this display

Version Windows 11 Professional Edition Version number 23H2 Installation date: ‎2023/‎10/‎3 Operating system version 22631.4317 Experience Windows Feature Experience Pack 1000.22700.1041.0

darshankawar commented 3 weeks ago

Can you provide content of flutter/.pub-cache/hosted/pub.dartlang.org/tencent_cloud_chat_sdk/ ? If you try to add Flutter's first party plugin (ex: video_player, image_picker) to see if you still get same error ?

Junkmer commented 3 weeks ago

The cause of the problem has been found, the permission problem. The flutter cmake script in Android studio cannot be executed successfully because of the permission problem of Powershell in Android studio. When I select "Start Android Studio as administrator", Execute flutter run -d windows running successfully, in order to prevent others encounter, here hope flutter official can fix or add the next description

darshankawar commented 3 weeks ago

@Junkmer Flutter needs to be installed in a directory where the current user has write permissions so make sure the path where you have installed Flutter has proper / required permissions. Also, check if this is helpful or not and make sure you have installed the sdk properly per https://docs.flutter.dev/get-started/install/windows/desktop

Junkmer commented 3 weeks ago

Thanks, I'll try changing it.

Junkmer commented 3 weeks ago

image image

Running Android studio as an administrator can image

huycozy commented 3 weeks ago

Does this happen if you run Flutter from a singular Powershell session (without being embedded inside any IDE)? Can you confirm you have installed the sdk properly as mentioned above?

Junkmer commented 3 weeks ago

No, unless I run it as an administrator. image

huycozy commented 3 weeks ago

Thanks for the update. But I would like to confirm more about plugins you added:

Could you also test with our 1st party plugin (path_provider for eg which supports windows platform)? Thanks a lot! [^1]

[^1]: Please provide the information (output logs) in text format instead of a screenshot for better readability and investigation, see avoid posting screenshots of text.

Junkmer commented 3 weeks ago

OK, I'll try it at night

Junkmer commented 2 weeks ago

image

image

image

Adding path_provider can run successfully, but adding tencent_cloud_chat_sdk or bitsdojo_window still cannot run

darshankawar commented 2 weeks ago

but adding tencent_cloud_chat_sdk or bitsdojo_window still cannot run

These are third party plugins. Please reach out in their dedicated repo to know if there's an issue with them or not.

Junkmer commented 2 weeks ago

I don't quite understand. If it's a problem with the third-party library, why can it be run as an administrator? And only my Windows 11 has the problem, while others have no problem, and my Macos has no problem either. It's very strange.

darshankawar commented 2 weeks ago

Could be that the plugins you are using may not be having CMake files. You may compare it with the plugins with which it works. See https://github.com/flutter/flutter/issues/62059#issuecomment-662666870