运行Flutter示例应用时弹出构建失败报错,模拟器无法找到应用
Hey there, let's work through your Flutter setup issues step by step—this kind of hiccup is super common when you're just getting started, so I've got some practical fixes to try out.
Fixing the "FAILURE: Build failed with an exception" Error in VS Code
This error usually boils down to configuration mismatches or cached build data. Here's what to check:
- Run
flutter doctorto diagnose gaps
Pop open the VS Code terminal and runflutter doctor—this tool will scan your entire setup and point out missing components, unaccepted licenses, or misconfigured paths. If you see red Xs next to Android-related items, runflutter doctor --android-licensesand follow the prompts to accept all required licenses. - Clean your project and rebuild from scratch
Cached build files are a frequent culprit. Run these commands in order:
This wipes old build artifacts, reinstalls dependencies, and starts a fresh build.flutter clean flutter pub get flutter run - Double-check your SDK paths in VS Code
Open VS Code settings (Ctrl+, on Windows/Linux, Cmd+, on Mac), search for "Flutter SDK Path" and "Android SDK Path" to confirm they point to the correct folders where you installed these tools. If you're unsure where they live,flutter doctorwill show you the expected paths. - Troubleshoot Gradle issues
A lot of build failures tie to Gradle. Head to your project'sandroid/gradle/wrapper/gradle-wrapper.propertiesfile and make sure the Gradle version matches what your Flutter SDK expects. Also, ensure your internet is stable—Gradle often fails when it can't download required dependencies.
Fixing the Missing App in Android Emulator
If your emulator launches but the app is nowhere to be found, try these steps:
- Confirm you're deploying to the right emulator
When you runflutter runin VS Code, a list of available devices will pop up. Make sure you select the emulator that's currently running—sometimes VS Code defaults to a connected physical device or an emulator that hasn't fully loaded. - Uninstall leftover app instances
Old cached app versions can block new builds. Open the emulator's app drawer, find any existing copies of your sample app, and uninstall them. You can also runflutter uninstallin the terminal to remove the app directly from the connected emulator. - Enable USB Debugging on the emulator
Even emulators need this! Go to Settings > About Phone > Tap "Build Number" 7 times to unlock Developer Options, then go back to Settings > Developer Options and turn on USB Debugging. This lets Flutter properly push the app to the emulator. - Cold restart the emulator
Emulators sometimes get stuck in a glitchy state. Close it completely, open Android Studio, launch the emulator again, and wait for it to fully load (give it a minute or two) before runningflutter runagain.
Give these fixes a try—most new Flutter devs resolve these issues with these steps. If you still hit walls, share the full error log from your VS Code terminal, and we can dig deeper!
内容的提问来源于stack exchange,提问作者Filip3KK
相关产品推荐
相关产品推荐

