DEV Community

Cover image for Red text on flutter run? Triage the build in this order before you search the error
Stacklyn Labs
Stacklyn Labs

Posted on

Red text on flutter run? Triage the build in this order before you search the error

You clone a Flutter project, run flutter run, and get a wall of red text. The tempting move is to paste the last line into a search engine. Usually that's the slow route.

Most first-build failures on a project someone else wrote don't come from the code. They come from the setup: a Flutter version below the project's minimum, the wrong Java, a missing SDK, or generated files that were never generated. A fixed triage order clears most of them before you ever need the exact error message.

Run each step from the project root, and retry the build after every step. If it works, stop.

Step 1: Ask flutter doctor first

flutter doctor -v
Enter fullscreen mode Exit fullscreen mode

Fix anything it flags before building. The -v flag matters: it prints the path after Java binary at:, so you can see which Java Flutter actually uses. That one line explains a lot of Gradle errors that look like they're about something else.

Step 2: Compare your Flutter version with the project's minimum

flutter --version
Enter fullscreen mode Exit fullscreen mode

Check it against the minimum in the project's README or setup guide. If you're below it, upgrade:

flutter upgrade
Enter fullscreen mode Exit fullscreen mode

A version that's too old often shows up as a pub error rather than a build error, for example:

The current Dart SDK version is X, requires ^3.9.2
Enter fullscreen mode Exit fullscreen mode

Other forms of the same problem: "SDK constraint" errors and "Version solving failed". The fix is the same in every case: flutter upgrade, then flutter clean && flutter pub get.

Step 3: Build Android with Java 17

Android builds expect JDK 17 or newer. In Android Studio, go to Settings > Build Tools > Gradle > Gradle JDK and pick 17 or newer. From the terminal you can point Flutter at a specific JDK:

flutter config --jdk-dir "path/to/jdk17"
Enter fullscreen mode Exit fullscreen mode

Gradle failures read differently on every machine, but the usual cause is the same: an old Android Studio or a Gradle JDK below 17. Our recent templates use Android Gradle Plugin 9 with Gradle 9, and a project on that setup needs a current toolchain. So if sync fails, update Android Studio to the latest stable version, check this setting again and run flutter clean before you read the stack trace.

Step 4: Clean and fetch packages

flutter clean
flutter pub get
Enter fullscreen mode Exit fullscreen mode

This clears stale build output and restores dependencies. It's cheap, so it belongs early in the order.

Step 5: Generate code if a .g.dart file is missing

Projects that use Hive CE or Isar rely on generated adapters. If the compiler complains about a missing .g.dart file or an undefined registerAdapters, the code generator hasn't run yet:

dart run build_runner build --delete-conflicting-outputs
Enter fullscreen mode Exit fullscreen mode

Depending on the project, you may need it on a fresh download, and you need it again every time you change a model.

Step 6 (iOS only): Install pods

cd ios && pod install && cd ..
Enter fullscreen mode Exit fullscreen mode

If CocoaPods itself errors, the usual cause is stale pods or an outdated local spec repo. Reset them:

cd ios
rm -rf Pods Podfile.lock
pod repo update
pod install
cd ..
Enter fullscreen mode Exit fullscreen mode

If the error mentions a deployment target, make sure the platform line in ios/Podfile matches the project's iOS minimum (for example platform :ios, '14.0'), then run pod install again.

Still failing? Now read the message

After those six steps, the leftovers are specific and quick to recognise:

Message Cause Fix
No Android SDK found Android Studio missing, or SDK in a custom folder Install the SDK and command-line tools, run flutter doctor --android-licenses, or flutter config --android-sdk <path>
Gradle runs out of memory org.gradle.jvmargs too high for your machine Lower it in android/gradle.properties, for example -Xmx4G
Namespace not specified App ID changed, Android files disagree Match namespace and applicationId, move MainActivity.kt and fix its package line
Signed with the debug key android/key.properties not found Create the upload keystore and key.properties
Building with plugins requires symlink support Windows without Developer Mode start ms-settings:developers, turn it on, flutter pub get
app_localizations.dart not found Translations not generated flutter pub get or flutter gen-l10n

One more Gradle gotcha: an error can name a plugin when the real problem is your JDK. That's why Java sits at Step 3 and not at the end.

Why the order matters

Each step is cheaper than the one after it, and each removes a whole class of errors. Guessing from the last line of a stack trace skips that, and every wrong guess costs you another full build. Work the list top to bottom and the error that's left, if any, is usually the real one.


Further reading: Flutter Build Errors After Purchase: Troubleshooting Guide.

Which build error cost you the most time on a project you didn't write, and what turned out to be the cause?

Top comments (1)

Collapse
 
hyunsoo_xenoci profile image
Hyunsoo Ju •

Good order, and putting Java before the stack trace is exactly right. Two things I'd add to step 6 from cloning other people's Flutter apps on a Mac:

  1. Run flutter build ios --config-only (or one flutter run for iOS) before pod install. On a fresh clone ios/Flutter/Generated.xcconfig doesn't exist yet, and pod install fails with a message about FLUTTER_ROOT or a missing Generated.xcconfig that looks like a CocoaPods problem but isn't.
  2. If pod install dies inside Ruby with an ffi error, it's usually the system Ruby. brew install cocoapods (or a Ruby from rbenv) fixes it faster than any pod cleanup.

And the one that cost me the most time on someone else's project: an IPHONEOS_DEPLOYMENT_TARGET set per pod lower than the Podfile platform, which only failed on archive, not on flutter run. A small post_install hook that sets every pod target to the app's minimum made it go away.