You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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’s android/build.gradle file, 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

    1. Check your project’s android/gradle/wrapper/gradle-wrapper.properties to find the required Gradle version (look for distributionUrl, e.g., gradle-7.5-all.zip).
    2. Download that exact version from the Gradle official site, unzip it to a local path like E:\gradle\gradle-7.5.
    3. Update the distributionUrl in the properties file to point to your local copy:
      distributionUrl=file\:///E\:/gradle/gradle-7.5-all.zip
      
      Note: Use escaped backslashes or forward slashes for Windows paths.
  • 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

    1. Open Command Prompt and run java -version + javac -version— aim for JDK 11 (Flutter’s most compatible version for Android).
    2. 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).
    3. Add this line to android/gradle.properties to enforce the path for Gradle:
      org.gradle.java.home=E:/jdk-11.0.18
      
  • 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\Sdk
    

    Then run flutter doctor -v to check for missing licenses or components. If you see license errors, run:

    flutter doctor --android-licenses
    

    Type y to accept all licenses when prompted.

3. Deep Clean & Rebuild the Project

Sometimes residual build files cause issues— go beyond ./gradlew clean:

  1. Run these Flutter-specific clean commands:
    flutter clean
    flutter pub get
    
  2. Manually delete these folders from your project:
    • .dart_tool (root of project)
    • build (root of project)
    • android/build (inside the Android module)
  3. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 19:27:45