新建Flutter项目运行报错:'dar'未识别及Gradle加载失败求助
Hey, let's troubleshoot this issue step by step! Looking at your error messages and project path (E:\Intern\26-light & dar theme\untitled1), the root cause is clear: your project directory contains spaces and an ampersand (&) character, which breaks Windows command line parsing. The command line is interpreting & dar as a separate command instead of part of the path, hence the 'dar' is not recognized error—this then prevents Gradle from loading its wrapper properly, leading to the ClassNotFoundException for org.gradle.wrapper.GradleWrapperMain.
Here are the fixes you can try, starting with the simplest and most effective one:
1. Move your project to a path without special characters/spaces
Windows command line struggles with paths that have spaces, &, #, or other special symbols. Do this:
- Cut your Flutter project folder and paste it into a directory like
E:\Intern\LightDarTheme\untitled1(no spaces, no&or other special chars). - Close and reopen Android Studio, then open the project from the new path.
- Try running the app again, or execute
flutter runin the new project directory.
2. Regenerate the Gradle wrapper (if moving the project doesn't work)
If the path fix alone doesn't resolve the Gradle wrapper issue, try resetting the wrapper files:
- Delete the
android/gradlefolder, plus theandroid/gradlewandandroid/gradlew.batfiles from your project. - Open a terminal, navigate to your project's android directory:
cd android - Generate a new Gradle wrapper (use a version compatible with your Flutter SDK—Flutter 3.x typically uses Gradle 7.x, adjust if needed):
gradle wrapper --gradle-version 7.4 - Go back to the project root and run
flutter runagain.
3. Verify your environment configurations
Double-check these to rule out any underlying setup issues:
- Run
flutter upgradeto make sure you're on the latest stable Flutter SDK. - Confirm that
JAVA_HOMEandGRADLE_HOMEenvironment variables are set correctly, pointing to valid JDK and Gradle installations (no spaces in these paths either!).
内容的提问来源于stack exchange,提问作者Lakshan Kodithuwakku

