Flutter Desktop Linux build failed - flutter

When I try to build my app to Flutter Desktop its fail with this message:
Launching lib/main.dart on Linux in debug mode...
Exception: Build process failed
My configuration is:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.19.0-2.0.pre.142, on Linux, locale pt_BR.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 3.6)
[✓] Connected device (1 available)
Can anyone know how to fix this?
Thanks

I had the same issue.
First I ran flutter run -v -d linux, I followed the log and I noticed it an OS Error
Unhandled exception:
FileSystemException: Setting current working directory failed
So, I firstly switch to the master channel (solution for some people), run flutter upgrade and I was getting the same error.
My working dir is /home/xylia/Flutter\ Apps/github_pages and I felt it might be the space from the folder name (I had an issue like that once), so I created a new folder without space and it worked!
I am not totally sure if changing channel to master helped but there is no harm in doing it

I don't know if you already found a solution but for everyone having this problem, I solved it by doing the following:
Inside your project root directory delete the linux folder, like rm -rf linux.
Run flutter clean to delete the build folder and other related files.
Then run flutter create . to make flutter recreate your linux folder.

I had the same problem my fix was to create/run the flutter project on primary SSD/HDD drive.

In my case, it was a dependencies problem. I was trying to use svg_flutter package in a desktop app (which is not supported).
Try running flutter run -v -d linux and check if any error message corresponds with new packages that you added recently.

Related

Getting error : "Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead "

Im trying to build flutter web app on release mode using flutter build web(also tried flutter build web --no-sound-null-safety).When i do,im getting the below error.
D:\saves\reset_password>flutter build web
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
.dart_tool/flutter_build/1916f9367c0e6ad6c929bd88cf5227e5/web_plugin_registrant.dart:14:38:
Error: Null safety features are disabled for this library.
void registerPlugins([final Registrar? pluginRegistrar]) {
^
Error: Compilation failed.
Compiling lib\main.dart for the Web... 44.9s
Exception: Failed to compile application for the Web.
It works fine when i run it directly in debug mode using flutter run.
Note: I recently upgraded to flutter 3.0 and im using Android studio.
Below is my flutter doctor( i am aware of the android tools missing.since im building for web,i didnt pay much attention to it)
D:\saves\reset_password>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 3.1.0-0.0.pre.966, on Microsoft Windows [Version 10.0.19044.1706], locale en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
[√] Android Studio (version 4.1)
[√] VS Code (version 1.66.2)
[√] Connected device (3 available)
[√] HTTP Host Availability
! Doctor found issues in 1 category.
For me was launching flutter clean && flutter pub get on the cmd/terminal, the solution.
flutter build web worked on my local but not on my server, after sudo reboot it worked again. the above sugestet answer didnt work for me...
I had a similar problem.
It was on server based on Ubuntu.
In my case I had:
Target dart2js failed: Exception: Warning:
The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-3.3.19/lib/firebase_auth_web.dart:402:16:
Error: The method 'FirebaseAuthWeb.verifyPhoneNumber' has fewer named arguments than those of overridden method 'FirebaseAuthPlatform.verifyPhoneNumber'.
...
I discovered that a firebase_auth_web dependency had a deprecated version and wasn't used in the project. Hence I removed this dependency. After that the problem disappears.
The fix for this issue is now available on the stable channel 3.3.0. It was due to a change in one of the 3.0 builds that put null safe features in the web plugins registrant. Any web project without null safety would have been affected.
Delete /flutter/bin/cache folder.
Run flutter doctor.
Then, run flutter clean, flutter pub get and flutter build web.
Delete .dart_tool
flutter clean
flutter pub get
flutter build web
I fixed this error by myself.Here's what i did:
I found that there are few dependencies in pubspec.yaml file that are not used currently.I navigated to my .dart_tool\flutter_build\cb8031cdd1bfbcb95122aae4ad9a63d5\web_plugin_registrant.dart and found that those dependencies are being referenced inside registerPlugins().
I cleared all those unused dependencies shown in registerPlugins() and did the following steps:
1.flutter pub get
2.flutter clean
3.flutter build web
And VIOLA! The error went away and i got my files in the build\web folder.

can't build IOS

I encounter this error when i try to build for ios, i tried every solution i could find online
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
In file included from
/Users/ahmedaly/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_ios-6.0.13/ios/Classes/FLTURLLauncherPlugin.m:7:
/Users/ahmedaly/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_ios-6.0.13/ios/Classes/FLTURLLauncherPlugin.h:5:9: fatal
error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel
Encountered error while building for device.
example of the things i tried:
pod deintegrate
rm podfile.lock
rm pubspec.lock
flutter clean
flutter run
and just about anything similar you could immagine
i also tried removing the file from the path indicated and removing the dependency from pubspec.yaml but it didn’t work
flutter doctor output :
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.0, on macOS 11.6 20G165 darwin-x64, locale
en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2021.2.3)
[✓] VS Code (version 1.63.0)
[✓] Connected device (2 available)
• No issues found!
I found a solution in another question on Stack!
Backup ios/Runner folder.
Delete the ios folder.
Run flutter create (your project name). in the previous folder where you have your project(cd users/user/"projects_folder")
(this will recreate your ios folder).
Paste your Runner backup in the ios folder (into the project).
Open Runner.xcworkspace (into ios folder) and there, check the Version, the Bundle ID, all the info.
(If do you Have Firebase, you have to copy and paste again the Google Service-Info.Plist into the Runner folder (Always through Xcode) (If do you do this manually, it doesn't work).
Finally, flutter run and should work!
If flutter run fails:
cd ios
pod install
cd ..
flutter run

android-studio android-studio-dir location

I am trying to get flutter/android studios to work on linux and i am having an issue getting flutter to recognize my android-studio location.
I am able to run android-stuio, but when i try to tell flutter my install location via the android-studio-dir param i get something that doesn't work.
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.27.0-2.0.pre.78, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio
✗ android-studio-dir = ~/Downloads/android-studio/bin/
✗ Android Studio not found at ~/Downloads/android-studio/bin/
[✓] VS Code (version 1.53.1)
[!] Connected device
! No devices available
At location ~/Downloads/android-studio/bin/ i have the bin directory of my android studio install. This obviously doesn't work.
I have tried to look up what directory android-studio-dir needs to point at and it seems that i wants to point at a directory like /path/to/android/studio.
but in my install directory i dont have a studio directory to point at?
So my question is what should android-studio-dir point at?
I am able to run android studio by ./~/Downloads/android-studio/bin/studio.sh
So i am fairly confident i have android studio "installed" correctly.
For windows the commands are same like those from #Doc but take care of the slashes:
flutter config --android-sdk="C:/TestFolder/AndroidSDK"
flutter config --android-studio-dir="C:/Program Files/Android/Android Studio"
the commands are
flutter config --android-sdk="/home/user/Android/Sdk"
flutter config --android-studio-dir="/usr/local/android-studio"
Don't use the bin folder, just mark the root folder for both the sdk and the IDE. Also, use complete path.
A. To resolve your unrecognized sdk. issue, use following steps
Find your dir. location. You will find at same place
C:\users\UserName\AppData\Local\Android\SDK
Mine was at
C:\Users\SHARM\AppData\Local\Android\Sdk
Go to PowerShell and type
flutter config --android-sdk
"C:\users\UserName\AppData\Local\Android\SDK"
Change your Username above
PowerShell screenshot showing how I resolved unable to locate SDK issue
B. To resolve dir issue, type
flutter config --android-studio-dir "type directory name"
In my case, it was
flutter config --android-studio-dir "C:/Program Files/Android/Android Studio"
C. I have license issue so I am sharing here if in case you encounter it after fixing SDK and dir issue.
C.1 Open you Android Studio
C.2 On main screen, Click Advanced > SDK Manager
SDK Manager
C.3 Select SDK Tools
Check Android SDK Command-line tools and click ‘apply’.
Check Android SDK Command-line tools and click ‘apply’
C.4 Click Apply.
C.5 Your license issue will be resolved. You can test it by again going to PowerShell and type
flutter doctor
You will pass all tests like I did in photoflutter passed all tests
If you want to check your configurations for SDK, dir etc, just type flutter config and it will show you all configurations.

The current Flutter SDK version is 0.0.0-unknown

I am not using GIT. As i have seen some posts/questions where users are mentioning they are using GIT and due to that they are getting the error.
Yesterday, I added Image Cropper Plugin and then I restarted the machine. After the restart, it starts giving the error.
The current Flutter SDK version is 0.0.0-unknown.
Because image_cropper 1.2.1 requires Flutter SDK version ^1.12.13 and no versions of image_cropper match >1.2.1 <2.0.0, image_cropper ^1.2.1 is forbidden.
So, because demoapp depends on image_cropper ^1.2.1, version solving failed.
pub get failed (1; So, because demoapp depends on image_cropper ^1.2.1, version solving failed.)
Exited (1)
I run Flutter version command -> Below is the output.
Flutter 1.12.13+hotfix.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f139b11009 (6 weeks ago) • 2020-03-30 13:57:30 -0700
Engine • revision af51afceb8
Tools • Dart 2.7.2
I did Flutter Clean and Flutter Pub Get they both didn't fix the issue.
I run Flutter Doctor and here is the output.
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the
Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[✓] Android Studio (version 3.1)
[✓] VS Code (version 1.44.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
I am not using Xcode from the beginning.
Any advice on how to fix this issue.
Edit
I checked the path by running echo $PATH.
/Users/rahul/Desktop/flutter/bin
Path is also there.
Edit 2
Flutter Upgrade also didn't helped.
First Restart your system.
Open your downloaded Flutter SDK zip folder (folder you get when you download flutter sdk from official website) and copy packed-refs and config file which is under <flutter_windows_1.22.5-stable.zip\flutter.git> folder
Remove these two files from the existing flutter sdk location in your system(which you extracted earlier) and paste these files again.
Again open android studio and try again by clicking Get dependencies button.
Click on run application.
App will run successfully.
for the new git version you need to config the path of your projet like this
git config --global --add safe.directory D:/path_were_flutter_is_locate/flutter
if it happened to you on Mac OS just install homebrew like on the description on
https://brew.sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then install git
brew install git
I faced this error because I have multiple user on my system so when i trying to run my project from not-admin user i get this error. i resolved it by using this command
git config --global --add safe.directory C:/flutter
"C:/flutter": is your flutter sdk folder path
Try running flutter doctor if it still shows the flutter version is 0.0.0-unknown, Then mostly your flutter installation is corrupted.
Please follow the steps mentioned in the below link.
https://github.com/flutter/flutter/wiki/Workarounds-for-common-issues#flutter-installation-corrupted
Try running git checkout stable in your flutter installation folder.
I had same issue in Windows and this fix works for me
(Sorry if my english is bad :( )
my flutter installation was git clone --depth=1
so I removed the whole dir: rm -rf flutter
then git clone once again. this time the full repository.
I think it solved the issue.
pub get works again, and flutter can build/run.
The flutter tool determines the Flutter SDK version from the Git tags in your local Flutter Git repository. If you've created a shallow Git clone (i.e., used something like git clone --depth=... or done other manipulations to your Git repository that lost the tag information, the flutter tool will be unable to determine the version number and will report 0.0.0-unknown.
If you find yourself in this state, your best course of action would be to reinstall the Flutter SDK in a supported way (i.e., by following the installation instructions).
After uninstalling and reinstalling flutter you have to create a new flutter app using flutter create app-name. trying to work on the same project will not solve the issue.
This problem fed me up for days.
How i solved this is issue is that i just upgraded the flutter and then deleted the current project while copying the code and created a new project and then pasted the code to the new project
Hurray the issue was solved!!!
for me its due to different issue. Where i should run flutter as normal user not admin. hope this helps.
Go to github page of flutter_image_cropper package, fork it in your space, then change its sdk requirement in its pubspec.yaml file, commit it, push it, now in your project, while importing this package, provide path of your github link to your forked repository ending with .git. It will work perfectly.
Also you can refer Github page for common issues

Flutter taking an unexpectedly long time for connecting to browser

I'm building flutter web project and after implenting login page via firebase I ran flutter run -d chrome.
But it's stuck while attempting to connect to browser, its just attempting for endless time without giving any error messages. Status bar:
λ flutter run -d chrome
Launching lib\main.dart on Chrome in debug mode...
Building application for the web... 20,2s
Attempting to connect to browser instance..
(This is taking an unexpectedly long time.) \
Flutter doctor:
λ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.10.11-pre.2, on Microsoft Windows [Version 10.0.18362.356], locale ru-RU)
[X] Android toolchain - develop for Android devices
X Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/setup/#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, set ANDROID_HOME to that location.
You may also want to add it to your PATH environment variable.
[√] Chrome - develop for the web
[!] Android Studio (not installed)
[√] VS Code (version 1.38.1)
[√] Connected device (2 available)
! Doctor found issues in 2 categories.
pubspec.yaml:
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
firebase: ^5.0.0
firebase_auth:
Try with flutter run -d web-server, then open URL on Chrome manually.
Remove all unused dependencies
flutter run -d web-server
The answer mentioned by #Giampaolo is a great workaround!
Same issue here. When trying the sample project, it works. I think the problem has something to do with dependencies, but have not figured out in detail.
Update:
Could be related: https://github.com/flutter/flutter/issues/40876
and https://github.com/flutter/flutter/issues/39998
Update #2:
I could reproduce the issue a described in
https://github.com/flutter/flutter/issues/39998
1) Create fresh flutter project with web support -> works.
2) add import 'dart:io'; to main.dart -> blank screen
Same issue . It wasn't able to get the instance of browser.
I tried removing unused imports, in my case "import 'dart:ffi';" this was the unused import and ta daa ... it worked !!!.
i just don't know what exactly the problm was.
Same issue: It use to take lot of time to load and 'r', the hot reload command never worked.
For me cleaning builds by "flutter clean" did the magic.
I have fixed that issue by installing the latest JDK and JRE and added both path to environment variables. it fixes my flutter speed but flutter run and apk building still taking the same.