Flutter - Could not find a command named "-" - flutter

I'm new to flutter, when I created a new project of flutter and run it, this appears :
Using hardware rendering with device AOSP on IA Emulator. If you notice graphics artifacts,
consider enabling software rendering with "--enable-software-rendering".
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Could not find a command named "-".
Usage: dart [<vm-flags>] <command|dart-file> [<arguments>]
Global options:
-h, --help Print this usage information.
-v, --verbose Show additional command output.
--version Print the Dart SDK version.
--enable-analytics Enable anonymous analytics.
--disable-analytics Disable anonymous analytics.
Available commands:
analyze Analyze the project's Dart code.
compile Compile Dart to various formats.
create Create a new project.
fix Apply automated fixes to Dart source code.
format Idiomatically format Dart source code.
migrate Perform a null safety migration on a project or package.
pub Work with packages.
run Run a Dart program.
test Run tests in this package.
Run "dart help <command>" for more information about a command.
See https://dart.dev/tools/dart-tool for detailed documentation.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 510ms
Exception: Gradle task assembleDebug failed with exit code 64
I'm stuck with this problem, how to solve this?

I have solved this problem. I run this project in my D: directory while my flutter and android SDK was installed in C: directory. So, when I tried to create flutter project in C:, it worked. But, I still can't configure why this problem happened.

#Papskipapap may I ask, if running your project on D: also inculded some path name which contained a "-" (dash) in it? As a rule of thumb: Keep pathnames easy, i.e. without blanks or special characters other than "_" (underscore), many tools just can not handle those...

Related

Flutter Null Safety issue

This application is not configured to build on the web.
To add web support to a project, run flutter create ..
Launching lib\main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
package:flutter_speed_dial
For solutions, see https://dart.dev/go/unsound-null-safety
Unhandled exception:
You will need at least version 3.0.0 of that package to have null safety.
Given that they are at version 5.0.0 right now, you should probably update your packages every once in a while.
If you want to run without latest version you need to Update the Configuration File,
Edit Configuration
Then,
Add --no-sound-null-safety in Additional run args.
Add Command in Additional run args
Then, Click Apply and Run the app.
Edited:
you will need to latest version and if you want to run without latest version you need to run this command
$ flutter run --no-sound-null-safety

How do you compile a flutter application?

I'm seeing that I can introduce a compilation error in my dart code but flutter build ios will still successfully run. If I flutter run -d [my-simulator] the compile error will immediately be presented in a red screen on the simulator but I can't currently easily do this in a CI type check.
Is there are cli command I can run to ensure that all of the dart code is free of compile errors?
You can run dart analyze or flutter analyze commands.
More info

Flutter Gradle task assembleDebug failed with exit code 1 zip END header not found

Hello I am new to Flutter I have setup flutter with android studio 4.2.1, and every thing is fine. When I try to run it; it show me following error
I see too much questions but it is not helpfull for me
flutter doctor run no issue found
Hers is doctor result
Here is my enviroment variable
can any one guide me how can I run the flutter. I am lunching it in a chrome
exception in thread "main" java.util.zip.ZipException: zip END header not found at
java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1567) at
java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1462) at
java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1469) at
java.base/java.util.zip.ZipFile$Source.(ZipFile.java:1274) at
java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1237) at
java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:727)
at
java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
at java.base/java.util.zip.ZipFile.(ZipFile.java:247) at
java.base/java.util.zip.ZipFile.(ZipFile.java:177) at
java.base/java.util.zip.ZipFile.(ZipFile.java:191) at
org.gradle.wrapper.Install.unzip(Install.java:214) at
org.gradle.wrapper.Install.access$600(Install.java:27) at
org.gradle.wrapper.Install$1.call(Install.java:74) at
org.gradle.wrapper.Install$1.call(Install.java:48) at
org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48) at
org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at
org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Exception: Gradle task assembleDebug failed with exit code 1
I recently Solved this problem.
This Problem came from gradle file is corrupted in my system.
I'm using Linux so this steps almost same in windows also. This answer is for any gradle version.
Open File Manager:
enable Show hidden folder from top menu bar.
You may find this location : .gradle>wrapper>dists.
In Linux: Home > .gradle > wrapper > dists.
In Windows: C:>Users>{PC Name}>.gradle>wrapper>dists
Method 1
Go inside gradle-6.5-all > dists > 2oz4ud9k3tuxjg84bbf55q0tn. '2oz4ud9k3tuxjg84bbf55q0tn' may be different in your PC.
Delete all files in that folder and download required file manually: https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
after download paste freshly downloaded zip file in that folder.
Run your project flutter run -v
Method 2
Try this if you have fast & stable internet connection.
Delete that gradle-6.5-all folder.
Open project in VS code or Android Studio and open terminal.
Run this command flutter run -v
Method 3
Flutter Doctor will give right result.
Open Android Studio
Create new flutter project
Click on Tools > flutter >Flutter for editing in android studio
and wait, flutter doctor takes time to identify problem.
Use this link for download gradle file.
Replace 6.5 with your gradle version.
https://downloads.gradle-dn.com/distributions/gradle-6.5-all.zip
I hope this answer helpful for you.
Please use the below command
1.Mac User :
rm -rf ~/.gradle
2.Windows User :
remove the .gradle file
.gradle file location -> C:\Users\myUser
I solve this error by updating the gradle plugin/version. I have as part of my configuration:
Windows 10
Android Studio 4.2.1
Java 11: Android Studio 4.2.1 don't have support for JDK 16, so, I installed JDK 11, and configured the AS (how to change the jdk in AS) to use this older JDK
Gradle 7.0.1
By default, when you create a new Flutter project, the IDE created it with basic standard configurations, so you have to change this configs to fit your current config. For that, you need to update the gradle config in the flutter project, as follow:
in android/gradle/build.gradle file: update the gradle plugin to 4.2.0 in the dependencies section, like this:
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
//more dependencies
}
in android/gradle/wrapper/gradle-wrapper.properties file: update the gradle version, in this case I have the 7.0.1, feel free to use another one, like this
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-all.zip
//more attributes
After you change the gradle config, run this commands in your project:
flutter clean : clean the project
flutter pub get : update your dependencies
flutter run : run the project. Now it must work, at least it work for me
I faced the same problem in VSCode when I wanted to run the Flutter app I got that error, so after lots of debugging and research, I found the solution. it's pretty easy, just follow these steps:
In windows 10:
1. Open flutter project in a Text-Editor like VSCode.
2. Open android -> gradle -> wrapper -> gradle-wrapper.properties
3. You will find "gradle-6.7.1.all.zip" inside gradle-wrapper folder
4. Go to this path: C:\Users\your-user
5. Then go to the wrapper->dists and find "gradle-6.7.1.all" folder
5. Delete this folder.
6. Then come to VSCode and open Terminal.
7. Please make sure that you have stable internet connection then type this command in terminal
8. flutter run
I hope this solution can help you!
I solve this error by deleting the .gradle folder.
This location is gradle folder
In Windows: C:> Users> {PC Name}>. Gradle
After deleting this folder, you only need to run the application again in Android Studio. At this point, Android Studio starts downloading the deleted folder automatically.
enter image description here
This error is caused by corrupted gradle files, this is either due to incomplete downloads due to network issues. To solve it easily download the gradle zipped file from https://downloads.gradle-dn.com/distributions/gradle-6.7-all.zip and paste on the .gradle directory as shown below if you are on linux
enter image description here
I try all method but it did not work for me so i decided to location the gradle-wrapper.properties in the andriod folder then i change the distribution gradle link to a more recent gradle link.
Welcome SO.
Java 16/latest version is not fully compatible with the Gradle 6 at this moment. Try to use java 11 or 8, it will resolve your issue.

Flutter - Gradle task assembleDebug failed

When you run flutter run, such an error is displayed, when checking flutter doctor no error, what is the reason?
I was facing the same issue for my project earlier and found the solution as below.
I have changed the Gradle wrapper properties distribution URL version to: 5.5.1-all which was available in my system.
Due to some reason, the android studio was fetching the latest version which was not in my system.
Problem:
Zip error occurs while compiler tries to wrap code with Gradle wrapper properties.
If the required files are missing or not properly available after downloading, this error occurs.
Solutions:
1) Redownload the Gradle which you are using currently.
2) Change the version of Gradle wrapper property version available in your system.

flutter is not running on windows

After installing flutter and running my emulator it stops at initializing gradle on android studio and on vs code.
It outputs:
this is taking an unexpectedly long time.
I ran flutter doctor and no issues and also flutter doctor -v and still no issues. I tried flutter upgrade but still no difference.
What is the next thing to try?
flutter error log
It looks like it is just taking forever to start; You can read the thread on the issue on
Github:
To summaries: here is one of the issues: Downloading 400mb of dependencies
Solved Initializing gradle problem
The problem is that when first time we are trying to run our flutter
project it does not have the required flutter gradle file. The
required file size that gradle downloads is about 300-400MB that's why
it takes so much time. Following are the steps:
Run your project by clicking on the 'Run' button or flutter run in the command terminal
Then go to the place where your .gradle file is located (usually it is in the C:\Users). In the .gradle folder there is file
name as wrapper in this there is dists folder. In dists folder there
is gradle folder which is being downloaded.
wait till the gradle file is being downloaded and after sometime your project would compile.
its working thaaaaaanks
I am new to mobile development; Everything takes eternity.
Solved this issue by removing all the gradle files from
C:\Users\.gradle\wrapper\dists
Now when you run your flutter app, it will automatically download the required gradle files.
Enjoy!!!