Skip to content

fix: getBuildSettings picking up wrong target#2801

Open
divyanshu-patil wants to merge 1 commit into
react-native-community:mainfrom
divyanshu-patil:fix/wrong-target
Open

fix: getBuildSettings picking up wrong target#2801
divyanshu-patil wants to merge 1 commit into
react-native-community:mainfrom
divyanshu-patil:fix/wrong-target

Conversation

@divyanshu-patil
Copy link
Copy Markdown

Summary

When a project contains multiple build targets where a non-app target (such as a
.framework target) appears before the .app target in the Xcode build settings
output, the CLI incorrectly installs and launches the framework instead of the app.

Root Cause

The code correctly filters applicationTargets to only include .app targets,
but then uses the index from the filtered array to look up build settings in the
original unfiltered settings array:

const targetIndex = applicationTargets.indexOf(selectedTarget);
return settings[targetIndex].buildSettings;

For example, given the following build settings output from xcodebuild -showBuildSettings -json:

[
  { target: "React-Core", WRAPPER_EXTENSION: "framework" },  // index 0
  { target: "Mattermost", WRAPPER_EXTENSION: "app" },        // index 1
]

After filtering by WRAPPER_EXTENSION === 'app':

applicationTargets = ["Mattermost"]  // index 0 in filtered array

applicationTargets.indexOf("Mattermost") returns 0, but settings[0] is
React-Core, not Mattermost, so the wrong build settings are returned.

applicationTargets after filtering is ["Mattermost"], so
applicationTargets.indexOf("Mattermost") returns 0. However settings[0]
points to React-Core, not Mattermost, causing the wrong build settings to
be returned.

Fix

Look up the correct entry directly from the settings array by target name
instead of relying on the filtered index:

return settings.find(s => s.target === selectedTarget).buildSettings;

Additionally, improved the default target selection to prefer a target whose
name matches the scheme before falling back to the first available target:

let selectedTarget =
  applicationTargets.find(t => t.toLowerCase() === scheme.toLowerCase())
  || applicationTargets[0];

Test Plan

  1. Set up a React Native project that produces multiple build targets including
    at least one .framework target appearing before the .app target in the
    build output (e.g. Mattermost Mobile).
  2. Run npm run ios or react-native run-ios.
  3. Verify the correct .app target is installed and launched on the simulator
    instead of the .framework target.

Before fix: CLI installs React.framework and attempts to launch
org.cocoapods.React, resulting in:

App installation failed: Unable to Install "React"
error Failed to launch the app on simulator

After fix: CLI correctly installs and launches the .app target.

Checklist

  • Documentation is up to date.
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, my test plan has linked these CLI changes into a
    local react-native checkout.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant