Flutter Windows: cannot build App error MSB8066 - flutter

I am getting this error while building for windows
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238,5): error MSB8066: Custom build for 'D:\DSI projects\sanjali_app\build\windows\CMakeFiles\a6c8cc86bdf940a07f4885a881770ba0\flutter_windows.dll.rule;D:\DSI projects\sanjali_app\build\windows\CMakeFiles\9c479cc21d461e620769ab96f5bca778\flutter_assemble.rule' exited with code 1. [D:\DSI projects\sanjali_app\build\windows\flutter\flutter_assemble.vcxproj]
Exception: Build process failed.

Updated Aug 2021
Faced the same error for couple of hours, and none of the issue on Github or answer on StackOverflow seems to be working for me.
So after my research I found out that there is no specific reason why Error MSB8066 error occur, but it can be due to space in your project Folder path as mentioned by #aishamhasan or some other undetermined reason. In my case, there is a simple file that is missing.
Error detected in pubspec.yaml:
[ +2 ms] [ ] No file or variants found for asset: images/project_app.png.
In order to quickly find out what causing this problem, you can run your project from the command line instead of using run functionality on android studio.
flutter run -d windows -v
And inside your verbose, lookout for any error, or you can directly search for Error and then try to figure out what was causing the error.
Followed the same approach and I was able to resolve the error very quickly.

Sometimes I get this error too. I have found that it happens whenever I forget to add a final slash "/" when declaring an assets folder in pubspec.yaml. For example:
This will produce the error:
flutter:
assets:
- assets/
- assets/game_logos
Adding the final slash solves the error:
flutter:
assets:
- assets/
- assets/game_logos/

The solution that worked for me is that I deleted build folder/dir from my project

In my case I had an assets image that I removed from the folder but had the path in pubspec.yaml, so I deleted the path then the app could run in Windows.

Removing spaces on the Projects Folder Path Solves the Issue.
Flutter Issues

I got MSB8066 when I generate python bindings, and fixed this by disabling
BUILD_PYTHON_BINDINGS in CMakeLists.txt

This can happen for a few reasons, an asset's path is missing the slash:
So:
assets:
assets/image
While it should be like this:
assets:
assets/image/
With the slash at the end.
The other more normal one, and which could really be causing such an error, could be the following;
The directory your project is in contains a special character, for example:
C:\Users\Aurélio Fernam\Documents\Projets\my_project
As you can see, "Aurélio" contains a special character. This could be causing this error.
Also try not to have a folder with space in your project path, like this:
C:\Users\Aurélio Fernam\Documents\Projets\my_project
Notice that "Aurélio Fernando/" besides having a special character, contains a space.
This could also be a trigger.
After having moved the project to a better directory, run flutter clean and run the project normally.

I faced the same issue due to some errors were there in some of the dart files. Check for red-underlined errors in the dart files you may have missed. These errors don't allow the project to run. After resolving the errors the project is running fine.

Non-Alphanumeric Characters in the project name also cause it.

I played arround with json in my asset folder. I deleted it and missed to remove it from pubspec as well.

Deleting the build folder in my project fixed the issue for me, you can also run a flutter clean, then run your project again.

In my case I use:
flutter pub get

None of the above methods worked for me.
First, I get an export zip file from project. And extract its content.
And open it, instead of the main project.
Only this worked for me after 1 day. But don't know why!
UPDATE:
This error fix for me when run Android Studio as administrator.

Related

Flutter: MissingPluginException(No implementation found for method printPdf on channel net.nfet.printing)

guys!
I am developing a desktop POS application for a shop. The application should have a feature to print some docs and barcodes. I have used pdf package to generate pdfs, but I am having a trouble with installing and using the priting package on Windows.
The main problem is with isntallation. In the docs, it says you should add the following lines in
CMakeLists.txt
file:
...
set(PDFIUM_VERSION "4929" CACHE STRING "" FORCE)
set(PDFIUM_ARCH "x64" CACHE STRING "" FORCE)
...
I am very confused in which CMakeLists.txt I shall put, because flutter's windows folder includes multiple files with the same name and extension. (windows\CMakeLists.txt, windows\runner\CMakeLists.txt, windows\flutter\CMakeLists.txt)
I have put the same piece of code into these different files, but none of them worked.
It always gives some errors like below:
errors
The thing I wanted to accomplish is to just print a generated PDF:
code
I'm having the same issue
What I do is
Flutter clean
Flutter pub get
Uninstall the previous application
Run the app again
And it worked
go to your terminal and type the following commands.
Flutter clean
Flutter pub get
now close the app
build the app again
hope this works for you. thanks.

How to solve flutter.gradle and flutter.bat error?Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' && flutter.bat error

FAILURE: Build failed with an exception.
Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1
The solution that worked for me was:
Delete pubspec.lock file
Do flutter pub get
Run the project
And it worked.
I was able to get around this by running with null safety turned off. See this article for details.
dart --no-sound-null-safety run
flutter run --no-sound-null-safety
Maybe this outdated but should help someone.
Yesterday I Just restarted my pc and got this issue. I tried to search for the solution to this problem but nothing works in my case.
Solution
Just delete your flutter folder (Flutter Source) and then reinstall it. Your problem will solve.
First flutter clean then flutter run worked for me. Ref - https://github.com/flutter/flutter/issues/75139. Thanks to https://github.com/darshankawar
Definitely, the problem is from ur Gradle settings.
For me, when I got the error, the problem was from the app/build.gradle file. there, my minSdkVersion was set to 23, so I just changed it to 21 and the error was solved. I will suggest u check your targetSdkVersion is set to 29 and compileSdkVersion is 29. I hope this help you too
In my case, I moved the project folder to D:, flutter clean, pub get and it runs
(In my case this error occurred after I upgrade Android Sdk to 31)
Go to AndroidManifest.xml and Set this to all Activities with
android:exported=true
if you build apk with --obfuscate, don't forget add a dot to head of your
--split-debug-info directory.
flutter build apk --obfuscate --split-debug-info=/projectfolder/debug
to
flutter build apk --obfuscate --split-debug-info=./debug
worked for me
I tried flutter clean, reinstalling SDK. Nothing worked.
My folder name was not correct. It was mvvm,provider test I changed it to mvvm_provider_test. Then it worked.
This error happened when I added a certain plugin. It turned out that the plugin required a minSdkVersion of 18. After I changed that, I did a flutter clean and after that, flutter pub get. So from this, I believe if you just added a recent plugin before you started facing this issue you look through the documentation of that plugin for installation info.
Also, after I did the above I had to restart my pc.
In case you're using flutter in command-line, just add -v which will run any flutter command in verbose mode. This should show you the origin of an error.
Like for me I was building with --split-debug-info and the folder I chose did not exist
In my case, what worked for me was removing the pubspec.lock and then doing a flutter pub get in my vscode command console, being in my project. Then modify the android\app\build.gradle file. inside the file I had compileSdkVersion 30 and update to version 31, being as follows compileSdkVersion 31
Download new Flutter SDK and update flutter path in your project,
And try again
After i upgraded to Android Sdk 31, this came for me. What solved was the answer suggested by #Elias Fazel above but before doing that, i first needed to edit my gradle.properties file. Added the following line :-
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
This was suggested from here : How to fix the ''module java.base does not "opens java.io" to unnamed module '' error in Android Studio?
After this, i added this line to activity tag in AndroidManifest.xml & then it worked.
android:exported=true
Hope this helps.
In my case the issue was in Git
I have shifted to another branch which was merged and that causes the issue . then
checkout from the master to main problem solved .
For me, the problem was in my pubspec.yaml file. I made some changes to it got this error commented out those changes and now it works fine.
It's related with the Gradle, this issue comes when you have multiple Gradle versions in C:\Users\userName.gradle directory, the solution I made I deleted all directory files in .gradle directory, and restarted the IDE again with default gradle version who comes when you try to create the project at the first time 👉 (gradle-7.4-all.zip) this way works for me.
did face the same issue
"flutter pub cache clean" - running this command solved my issue
hope this becomes helpful
I did not find any solution so i did window again and all required software like flutter android studio etc.
and problem solved.

Tried archiving flutter project with no disc space left, can't fix errors

Question upfront: How can I thoroughly clean/repair my flutter project to allow it to run/build again?
I had been building and archiving (in Xcode) flutter projects without issue until just now.
My computer ran out of disc space mid archive and forced it to stop with "nonzero exit code".
I deleted a bunch of things on the computer to make space, and now it says there is >100gb left.
I was due for a flutter upgrade, so I ran flutter upgrade, which completed without error.
I closed android studio and Xcode and restarted my computer.
I ran flutter clean as well as clean within Xcode.
I can no longer run the app within flutter or run/archive within Xcode.
The exact errors seem variable, but here are some of them that I see:
Running from Xcode:
.../ios/Flutter/Flutter.framework/Headers/FlutterPlugin.h:292:13: Cannot find protocol declaration for 'FlutterTextureRegistry'; did you mean 'FlutterPluginRegistry'?
.../ios/Flutter/Flutter.framework/Headers/FlutterEngine.h:54:38: Cannot find protocol declaration for 'FlutterTextureRegistry'; did you mean 'FlutterPluginRegistry'?
.../.pub-cache/hosted/pub.dartlang.org/in_app_purchase-0.3.1+2/ios/Classes/FIAPReceiptManager.m:13:9: Could not build module 'Flutter'
Running from Flutter (I can't paste all of the errors... way too long):
^~~~~~~~~~~~~~~~~~~~~~
FlutterPluginRegistry
While building module 'Flutter' imported from .../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.h:5:
In file included from :1:
In file included from .../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/Flutter.h:54:
In file included from .../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/FlutterAppDelegate.h:11:
.../Documents/Flutter/patient_medical_record/ios/Pods/../Flutter/Flutter.framework/Headers/FlutterPlugin.h:395:11: note: 'FlutterPluginRegistry' declared here
#protocol FlutterPluginRegistry
^
3 errors generated.
In file included from .../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.m:5:
.../.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.5/ios/Classes/FLTPathProviderPlugin.h:5:9: fatal error: could not build module 'Flutter'
#import
~~~~~~~^
4 errors generated.
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Well this is a bummer because I can't find a clean solution, but for now I did fix it with the following:
Create a new flutter project
Copied over the lib files
Copied over other setup in random places (i.e. google services, android changes)
Copied over pubspec.yaml and ran packages get
It now works again. Clearly something went wrong in the Flutter-managed files that I don't understand. If someone else can think of a better solution to effectively reset the project, please share.

Unable to create flutter project

When running flutter create followed by project name, I receive this error:
Error: Error when reading '../documents/flutter/bin/cache/dart-sdk/bin/snapshots/pub.dart.snapshot': No such file or directory
Running "flutter pub get" in pics...
pub get failed (254; Error: Error when reading
'../documents/flutter/bin/cache/dart-sdk/bin/snapshots/pub.dart.snapshot': No
such file or directory)
I'm trying to create a new flutter project in xcode. How would I fix this?
'../documents/flutter/bin/cache/dart-sdk/bin/snapshots/pub.dart.snapshot': No
such file or directory
It seems like there may be files missing from your Flutter SDK. There should be a file in the Flutter SDK at bin/cache/dart-sdk/bin/snapshots/pub.dart.snapshot but this error suggests it's missing.
The easiest fix may be to delete the bin/cache folder which will cause Flutter to re-download the Dart SDK and other components when you next run flutter. This may take a little while depending on your connection, but is the simplest way to ensure the cache folder is complete. I would suggest closing all IDEs/editors when doing this.
I have same issue but the problem was windows defender at real time detection so the solution was to switch off it then create a project...

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.