Skip to content

Guide users when multiple Xcode projects are present - #188934

Closed
markst wants to merge 3 commits into
flutter:masterfrom
markst:fix-xcodebuild-multi-xcodeproj
Closed

markst wants to merge 3 commits into
flutter:masterfrom
markst:fix-xcodebuild-multi-xcodeproj

Conversation

@markst

@markst markst commented Jul 3, 2026 •

Copy link
Copy Markdown

Addresses the failure reported in #183747 (comment) and #78839.

When an iOS or macOS platform directory contains multiple .xcodeproj files, xcodebuild commands that do not specify -project fail with exit code 78. Automatically selecting one is unsafe because Flutter supports renamed host projects and the existing project lookup would otherwise choose the first match.

Following review feedback, this change keeps the existing project-selection behavior and instead provides a guided error explaining that additional Xcode projects should be moved into subdirectories, where they no longer conflict with host app project discovery.

Summary

  • Recognize exit code 78 from xcodebuild -list and confirm that the platform directory contains multiple .xcodeproj files
  • Detect the same ambiguous layout when Swift Package Manager dependency resolution fails
  • Name the projects found and guide users to move additional projects into a subdirectory, such as ios/Something/Foo.xcodeproj
  • Preserve support for renamed host projects rather than assuming Runner.xcodeproj

Test plan

  • flutter test packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart --name "getInfo"
  • flutter test packages/flutter_tools/test/general.shard/xcode_project_test.dart --name "prefetchSwiftPackages"
  • dart analyze packages/flutter_tools
  • dart format --output=none --set-exit-if-changed for all changed files

@markst
markst requested review from a team as code owners July 3, 2026 02:35
@github-actions github-actions Bot added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Jul 3, 2026
@google-cla

google-cla Bot commented Jul 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@markst
markst force-pushed the fix-xcodebuild-multi-xcodeproj branch from 5de53b4 to 2d5bca4 Compare July 3, 2026 02:41

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Flutter tools to explicitly pass the -project argument with the absolute path of the Xcode project when running xcodebuild -list and -resolvePackageDependencies. It also updates the logic for finding the Xcode project directory to prefer the default host app name (e.g., Runner) when multiple projects exist. The feedback suggests caching entity.basename in a local variable to simplify the directory search loop, and moving the early return check in prefetchSwiftPackages before the command list construction to avoid redundant allocations.

Comment thread packages/flutter_tools/lib/src/xcode_project.dart Outdated
Comment thread packages/flutter_tools/lib/src/xcode_project.dart Outdated
@hellohuanlin
hellohuanlin requested a review from vashworth July 9, 2026 21:44
Comment thread packages/flutter_tools/lib/src/ios/xcodeproj.dart Outdated
@LongCatIsLooong LongCatIsLooong added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 23, 2026
markst added 2 commits July 30, 2026 12:29
Swift package prefetch and xcodebuild -list failed when ios/ contained more than one .xcodeproj because no project was specified. Prefer Runner when resolving the host project name.
Cache entity basename in the project lookup loop and check for an in-progress Swift package fetch before building the xcodebuild command.
@markst
markst force-pushed the fix-xcodebuild-multi-xcodeproj branch from 84d1d59 to 5620e9a Compare July 30, 2026 02:31
@markst markst changed the title Pass -project to xcodebuild when multiple .xcodeproj exist Guide users when multiple Xcode projects are present Jul 30, 2026
@markst
markst force-pushed the fix-xcodebuild-multi-xcodeproj branch from 5620e9a to 843e6dc Compare July 30, 2026 03:16
`xcodebuild` cannot pick a project when the platform directory contains
more than one `.xcodeproj` and no `-project` is passed, so it exits with
code 78. That previously surfaced as an opaque crash.

Treat 78 as a recognised failure and, after confirming on disk that more
than one `.xcodeproj` is present, tool exit with a message that names the
projects found and explains that the extra ones belong in a subdirectory,
where they no longer interfere with the host app project lookup.
@markst
markst force-pushed the fix-xcodebuild-multi-xcodeproj branch from 843e6dc to a69ae6c Compare July 30, 2026 03:18
@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 30, 2026
Comment on lines +531 to +534
'Flutter identifies the host app by looking for a single .xcodeproj directly within '
'$platformDirectory/, so xcodebuild is unable to determine which project to use.\n'
'Move the additional Xcode project(s) into a subdirectory, such as '
'$platformDirectory/Something/Foo.xcodeproj, and update any references to them.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
'Flutter identifies the host app by looking for a single .xcodeproj directly within '
'$platformDirectory/, so xcodebuild is unable to determine which project to use.\n'
'Move the additional Xcode project(s) into a subdirectory, such as '
'$platformDirectory/Something/Foo.xcodeproj, and update any references to them.',
"Only the Flutter application's .xcodeproj (usually named Runner.xcodeproj) is allowed directly within $platformDirectory/.\n"
'Move any additional .xcodeproj directories into a subdirectory, such as '
'$platformDirectory/Foo/Foo.xcodeproj, and update any references to them.',

await _swiftPackageFetchStderrSubscription?.cancel();
});
if (exitCode != 0) {
throwToolExitIfMultipleXcodeProjects(hostAppRoot);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this here? We shouldn't throw here indiscriminately, we should check if it's failing due to the expected reason

@vashworth vashworth added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 13, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

This pull request is being closed because it has not been updated in the last 21 days after a request for more information.

If you are still working on this, please feel free to reopen it or file a new pull request.

Thanks for your contribution.

@github-actions github-actions Bot closed this Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform-ios iOS applications specifically team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels. waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants