Able to build ios app but unable to get build settings to deplou
Environment
System: OS: macOS 14.4.1 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 2.12 GB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 20.10.0 path: /usr/local/bin/node Yarn: version: 1.22.21 path: /usr/local/bin/yarn npm: version: 10.7.0 path: ~/toybox/app/node_modules/.bin/npm Watchman: version: 2023.12.04.00 path: /usr/local/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /usr/local/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 23.4 - iOS 17.4 - macOS 14.4 - tvOS 17.4 - visionOS 1.1 - watchOS 10.4 Android SDK: Android NDK: 22.1.7171670 IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10406996 Xcode: version: 15.3/15E204a path: /usr/bin/xcodebuild Languages: Java: version: 17.0.10 path: /usr/bin/javac Ruby: version: 2.6.10 path: /usr/bin/ruby npmPackages: "@react-native-community/cli": Not Found react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false
Description
I am able to consistently build the app and get good out put, but the command line tool never is able to deploy it.
I have gone into the built direct and done xcrun on my simulator so I know the generated binary is completely fine.
I dove into this package to figure out why it was unable to get the build settings and I'm able to mimic what I expect this line to be doing:
const buildSettings = child_process.execFileSync(
'xcodebuild',
[
xcodeProject.isWorkspace ? '-workspace' : '-project',
xcodeProject.name,
'-scheme',
scheme,
'-sdk',
getPlatformName(buildOutput),
'-configuration',
mode,
'-showBuildSettings',
'-json',
],
{encoding: 'utf8'},
);
xcodebuild -workspace <APPNAME>.xcworkspace -scheme <SCHEME> -sdk iphonesimulator -configuration Debug -showBuildSettings -json
And I get relatively valid results
This is the output I get:
success Successfully built the app
2024-05-07 13:06:15.701 xcodebuild[65545:562982] DVTPlugInQuery: Requested but did not find extension point with identifier 'Xcode.InterfaceBuilderBuildSupport.PlatformDefinition'. This is programmer error; code should only request extension points that are defined by itself or its dependencies.
error Failed to get build settings for your project.
Reproducible Demo
I don't know how to get this down into an easily reproducible situation, but at a minimum it feels like there is a bunch of missing logging or information as the actual errors don't make any sense.
If anyone has suggestions for a fix or cause I can try to break it down further (I have done all the suggested stack overflow answers)
hey @ToyboxZach did you resolve your issue?
Nope, and still no idea where to even go with breaking this down
@ToyboxZach that's really strange! Please make sure that version of xcodebuild in your shell matches the one that is used by Xcode, also try re-installing it to match target destination.
Thanks, I’ll try that, the weird thing is the build is working just fine, it’s just the ability to grab the build settings that seems to be weird.
hey @ToyboxZach @szymonrybczak were you able to solve this issue? I have tried already everything: upgrading OS, reinstalling Xcode but no luck. Also, xcodebuild used in shell matches the one used by xcode. I already run out of ideas :(
Yes I believe all my versions match, both are 15.4
And the build is completely fine, I can even launch the binary, its explicitly failing to launch because the tool is failing to get the build settings for some reason, even though the build settings look pretty valid to me.
I faced the same issue and spent quite a bit of time on it. I finally narrowed it down to the following line:
let selectedTarget = targets[0];
It looks like the cli fetches all the targets that have been defined and uses the first item from the list to install the app in the simulator.
In my case as seen in the screenshot, for some reason "React" is mentioned as a target at the top of the list. So the cli - although it builds the right target - when trying to install the build, tries to pick up this "React" build (which obviously doesn't exist). I ended up just removing the "React" target so that my scheme looks like the following:
I would suggest you to check your scheme and ensure that the right target is mentioned at the top of the list
it worked perfectly for me by following @chrishanthmathew91 recommendation:
- In Xcode, go to the menu bar and select Product > Scheme > Edit Scheme....
- In the Scheme editor, on the left-hand side, you’ll see a list of build actions (e.g., Build, Run, Test).
- Under the Build section, select the React target and click the - button.
Thanks!
That is not my problem, as I don't have a React target in my build section I only have my two Targets for the two different skus of my app + the Pods target
@chrishanthmathew91 @pvev btw if you have any troubles with targets selection logic you can also set it manually by specific --target option 👍
@ToyboxZach please provide more information, such as react-native version etc. Try also playing manually with xcodebuild command and with arguments there, maybe that'll help
I've been facing the same issue, so based on @szymonrybczak's message, I applied a patch with the following diff, which fixed the issue on my end:
diff --git a/build/commands/runCommand/getBuildSettings.js b/build/commands/runCommand/getBuildSettings.js
index 8e60c59cba33029e1a1e27129c31eee45207fe58..cae01ad81a08d401ae1d2a06861471a0a465fd4f 100644
--- a/build/commands/runCommand/getBuildSettings.js
+++ b/build/commands/runCommand/getBuildSettings.js
@@ -31,10 +31,16 @@ async function getBuildSettings(xcodeProject, mode, buildOutput, scheme, target)
encoding: 'utf8'
});
const settings = JSON.parse(buildSettings);
+ const fistIndexForAppTarget = Math.max(
+ 0,
+ settings.findIndex(({
+ buildSettings: bs
+ }) => bs.WRAPPER_EXTENSION === 'app'),
+ );
const targets = settings.map(({
target: settingsTarget
}) => settingsTarget);
- let selectedTarget = targets[0];
+ let selectedTarget = targets[fistIndexForAppTarget];
if (target) {
if (!targets.includes(target)) {
_cliTools().logger.info(`Target ${_chalk().default.bold(target)} not found for scheme ${_chalk().default.bold(scheme)}, automatically selected target ${_chalk().default.bold(selectedTarget)}`);
What appears to be the same issue but a slightly different error. The app builds but fails to find the correct target and doesn't install. Works perfectly when build and installed from XCode.
The error is failed to get the target build directory as seen here :
`node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error: Failed to get the target build directory.".] { code: 'ERR_UNHANDLED_REJECTION' } `
Tracked the error down to getBuildPath here ...
https://github.com/expo/react-native-community-cli/blob/master/packages/platform-ios/src/commands/runIOS/index.ts
As suggested above, removing the React target seems to resolve the issue but obviously isn't ideal.
React native 0.73.8 XCode 16.0
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.