VSCode中Flutter调试模式无法启动应用,Gradle assembleDebug失败
The Exact Scenario (Matching Your Issue)
I had a fully working Flutter setup where launching apps via AVD or physical Android devices in VS Code debug mode was smooth—until suddenly it broke. The error I got was identical to yours:
Launching lib\main.dart on Android SDK built for x86 in debug mode... Gradle task assembleDebug failed with exit code 1 Exited (sigterm)
I ran through the standard checks first:
flutter doctor -vshowed all environment configurations were completely normalflutter run -vthrew a "no connected devices" message, even though my AVD/physical device was clearly connected and recognized by Android Studio
The Quick Fix That Resolved Everything
After testing a few troubleshooting steps, this one command fixed the problem instantly:
flutter clean
Why This Worked (Likely Root Causes)
While we can't confirm the exact issue without deeper log analysis, this kind of unexplained failure almost always traces back to corrupted or conflicting build caches:
- Damaged build artifacts: Previous builds may have left corrupted cache files in the project's
builddirectory, causing Gradle to crash during theassembleDebugtask - Stale device connection cache: Flutter sometimes caches device connection state; if this cache glitches, it can fail to recognize a connected device even when it's active
- Temporary Gradle config conflicts: Minor dependency tweaks or project setting changes can leave Gradle in a broken state, and
flutter cleanwipes all these temporary states to start fresh
The flutter clean command deletes the project-wide build folder plus platform-specific build caches (like Android's .gradle directories), essentially resetting your project to a clean slate for building. It's the go-to fix for most weird, unexplained Flutter build failures.
内容的提问来源于stack exchange,提问作者nooxouille

