Flutter Demo应用无法运行且卡在Gradle构建环节问题求助
Hey there, let’s work through this Flutter app launch and Gradle hang issue together— I’ve debugged tons of these scenarios, so here’s a step-by-step breakdown of fixes to try:
1. Fix Gradle "assembleDebug" Hangs First
Gradle getting stuck is usually tied to network issues or misconfigured local paths. Let’s tackle that:
Swap to domestic Maven mirrors (if you’re in a region with slow access to Google/JCenter)
Open your project’sandroid/build.gradlefile, and replace the default repositories with faster alternatives (like Alibaba’s):buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } } // ... rest of buildscript code } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } } }Use a local Gradle distribution instead of downloading it every time
- Check your project’s
android/gradle/wrapper/gradle-wrapper.propertiesto find the required Gradle version (look fordistributionUrl, e.g.,gradle-7.5-all.zip). - Download that exact version from the Gradle official site, unzip it to a local path like
E:\gradle\gradle-7.5. - Update the
distributionUrlin the properties file to point to your local copy:
Note: Use escaped backslashes or forward slashes for Windows paths.distributionUrl=file\:///E\:/gradle/gradle-7.5-all.zip
- Check your project’s
Turn off Gradle Offline Mode
Open Android Studio →File→Settings→Build, Execution, Deployment→Gradle, make sure the "Offline work" checkbox is unchecked.
2. Verify JDK & Android SDK Configuration
Since you’ve installed tools on drive E, double-check alignment between system env vars and project settings:
Confirm JDK version and path
- Open Command Prompt and run
java -version+javac -version— aim for JDK 11 (Flutter’s most compatible version for Android). - In Android Studio, go to
File→Project Structure→SDK Location, set the JDK path to your E-drive installation (e.g.,E:\jdk-11.0.18). - Add this line to
android/gradle.propertiesto enforce the path for Gradle:org.gradle.java.home=E:/jdk-11.0.18
- Open Command Prompt and run
Sync Flutter with your Android SDK path
Run this command in Command Prompt to link Flutter to your E-drive SDK:flutter config --android-sdk E:\Android\SdkThen run
flutter doctor -vto check for missing licenses or components. If you see license errors, run:flutter doctor --android-licensesType
yto accept all licenses when prompted.
3. Deep Clean & Rebuild the Project
Sometimes residual build files cause issues— go beyond ./gradlew clean:
- Run these Flutter-specific clean commands:
flutter clean flutter pub get - Manually delete these folders from your project:
.dart_tool(root of project)build(root of project)android/build(inside the Android module)
- Restart Android Studio and try running the app again.
4. Quick Note on Visual Studio
You’re right— Visual Studio is only required for Windows desktop Flutter development. If you’re only building Android apps, you can safely ignore any Flutter doctor warnings about Visual Studio components. It won’t block your Android app from running.
If none of these fixes work, share the exact error message from your screenshot (copy the text if possible)— that’ll help narrow down the root cause even more.
内容的提问来源于stack exchange,提问作者014_Aryan Kumar Saw

