Skip to content

FLUTTER_BUILD_DIR environment variable - default to 'build' on macos#180251

Closed
WillCallahan wants to merge 4 commits into
flutter:masterfrom
WillCallahan:fix/FLUTTER_BUILD_DIR
Closed

FLUTTER_BUILD_DIR environment variable - default to 'build' on macos#180251
WillCallahan wants to merge 4 commits into
flutter:masterfrom
WillCallahan:fix/FLUTTER_BUILD_DIR

Conversation

@WillCallahan

@WillCallahan WillCallahan commented Dec 24, 2025

Copy link
Copy Markdown

This PR fixes an issue where the FLUTTER_BUILD_DIR environment variable is not defaulted for macOS builds, which can cause build failures.

When building a Flutter app for macOS, parts of the build process may rely on the FLUTTER_BUILD_DIR environment variable. If this variable is not set, the build can fail with a null-pointer exception. This change ensures that FLUTTER_BUILD_DIR is always defaulted to "build" if it is not set. This is done by creating a mutable copy of the environment in the xcode_backend.dart script and setting the default value there.

This change brings the macOS build behavior in line with the iOS build process, which already has similar logic. The following files provide evidence that "build" is the correct default:

Issues

Pre-launch Checklist

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team labels Dec 24, 2025
@WillCallahan
WillCallahan marked this pull request as ready for review December 24, 2025 03:24
@WillCallahan
WillCallahan requested a review from a team as a code owner December 24, 2025 03:24
@okorohelijah
okorohelijah requested a review from jmagman January 2, 2026 22:32
jmagman
jmagman previously requested changes Jan 2, 2026

@jmagman jmagman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @WillCallahan!

FLUTTER_BUILD_DIR should always be set in the Generated.xcconfig, for macOS as well as iOS. Despite the path,

xcodeBuildSettings.add('FLUTTER_BUILD_DIR=${buildDirOverride ?? getBuildDirectory()}');

actually is already called for macOS:
await updateGeneratedXcodeProperties(

It would be better to diagnose why the xcconfig isn't hooked up in the project. For a newly flutter created project, it is. It sets other things beside FLUTTER_BUILD_DIR, so this is just hiding a larger problem.

Do you have flavors set up? Are the configurations set up correctly in Xcode?

If it's not set, it may be appropriate to fail with an actionable error message, instead of continuing in a bad state as this PR does.

echoError('========================================================================');
echoError('ERROR: Unknown FLUTTER_BUILD_MODE: $buildMode.');
echoError("Valid values are 'Debug', 'Profile', or 'Release' (case insensitive).");
echoError('This is controlled by the FLUTTER_BUILD_MODE environment variable.');
echoError('If that is not set, the CONFIGURATION environment variable is used.');
echoError('');
echoError('You can fix this by either adding an appropriately named build');
echoError('configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the');
echoError(
'.xcconfig file for the current build configuration (${environment['CONFIGURATION']}).',
);
echoError('========================================================================');
exitApp(-1);

@WillCallahan

Copy link
Copy Markdown
Author

Ahh, I see; I performed a flutter upgrade and am missing this configuration. I will update this code so that we get a more descriptive exception message with how to fix it.

@vashworth
vashworth requested review from jmagman, okorohelijah and vashworth and removed request for jmagman January 8, 2026 22:39
@jmagman

jmagman commented Jan 22, 2026

Copy link
Copy Markdown
Member

Ahh, I see; I performed a flutter upgrade and am missing this configuration. I will update this code so that we get a more descriptive exception message with how to fix it.

That shouldn't be impacted by a flutter upgrade. Are you able to go back through your git history and see when it was removed? I am still not in favor of falling back to build for only one variable when the entire xcconfig isn't hooked up, you're going to run into all kinds of other problems. For example, your app version won't reflect your pubspec version, etc.

If we want to do this, it should be to hard-fail if an expected variable from the Generated.xcconfig isn't found, not do a soft fallback for only one of the variables, and print instructions or a link to instructions for how to hook it back up in the Xcode project.

@okorohelijah

Copy link
Copy Markdown
Contributor

@WillCallahan From Triage: We're putting this in draft. Please feel free to mark as ready for review when you want us to look at it again!

@okorohelijah
okorohelijah marked this pull request as draft February 5, 2026 22:37
@flutter-dashboard

Copy link
Copy Markdown

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@Piinks

Piinks commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Hey there @WillCallahan, is this a change you would like to continue working on?

@Hari-07

Hari-07 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

I can get this across the finish line if @WillCallahan isn't planning to

@Piinks

Piinks commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Thanks @Hari-07! I am going to close this since we have not heard back. Please feel free to pick it up if you would like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ios Owned by iOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Descriptive log on Flutter build when FLUTTER_BUILD_DIR environment variable isn't configured.

5 participants