Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS build fails via make run-ios but works with Xcode.app after upgrading react-native to 0.73.x #18548

Closed
siddarthkay opened this issue Jan 18, 2024 · 6 comments
Assignees

Comments

@siddarthkay
Copy link
Contributor

Problem

make run-ios fails with :

error Failed to build iOS project. "xcodebuild" exited with error code '65'. To debug build logs further, 
consider building your app with Xcode.app, by opening 'StatusIm.xcworkspace'.
info Run CLI with --verbose flag for more details.

Since we do not want to rely on opening Xcode app I try running xcodebuild with -verbose flag like this
cd ios && xcodebuild -workspace StatusIm.xcworkspace -configuration Debug -scheme StatusIm -verbose | xcbeautify

Thats when I get more details on the failure :

[FBReactNativeSpec] Running script [CP-User] Generate Specs
** BUILD FAILED **


The following build commands failed:
	PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/siddarthkumar/Library/Developer/Xcode/DerivedData/
	StatusIm-fxiitjbbybrcsqcxqartjfyvqxdo/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/
	FBReactNativeSpec.build/Script-46EB2E00021AC0.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)

My knee jerk reaction when i spotted DerivedData in the error message was that this issue could be cache related (but it wasn't)
I ran make xcode-clean and make clean just and this issue was consistently reproducible.

Notes

blocks #16721

@siddarthkay siddarthkay self-assigned this Jan 18, 2024
@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jan 18, 2024

First thing I try is to manually execute Script-46EB2E00021AC0.sh and It obviously fails, this time with an error message

[nix-shell:~/code/experiments/status-mobile/ios]$ sh /Users/siddarthkumar/Library/Developer/Xcode/
DerivedData/StatusIm-fxiitjbbybrcsqcxqartjfyvqxdo/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/
FBReactNativeSpec.build/Script-46EB2E00021AC0.sh
/bin/sh: /../../scripts/xcode/with-environment.sh: No such file or directory

inside this bash script, the path to WITH_ENVIRONMENT is determined like this
WITH_ENVIRONMENT="$RCT_SCRIPT_RN_DIR/scripts/xcode/with-environment.sh"

the variable RCT_SCRIPT_RN_DIR comes from here https://github.com/facebook/react-native/blob/0.73-stable/packages/react-native/scripts/react_native_pods_utils/script_phases.rb#L12

This could mean that since this variable is not properly set the script execution could fail.
Investigating further.

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jan 18, 2024

The issue is indeed in this script, after adding some logs to script_phases.rb we get the following logs :

RCT_SCRIPT_RN_DIR is -> /Users/siddarthkumar/code/experiments/status-mobile/ios/Pods/../../node_modules/
react-native/React/FBReactNativeSpec/../..

WITH_ENVIRONMENT is -> /Users/siddarthkumar/code/experiments/status-mobile/ios/Pods/../../node_modules/
react-native/React/FBReactNativeSpec/../../scripts/xcode/with-environment.sh

Node found at: /nix/store/ihji2bc16a7kj8d9z3xglj619v9ywmbi-nodejs-20.2.0/bin/node
cp: invalid option -- 'X'

we can see that cp command is failing, which seems to be the core problem.

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jan 18, 2024

so -X is used along with cp here at : https://github.com/facebook/react-native/blob/0.73-stable/packages/react-native/scripts/react_native_pods_utils/script_phases.sh#L107

moveOutputs () {
    mkdir -p "$RCT_SCRIPT_OUTPUT_DIR"

    # Copy all output to output_dir
    cp -R -X "$TEMP_OUTPUT_DIR/." "$RCT_SCRIPT_OUTPUT_DIR" || exit 1
    echo "$LIBRARY_NAME output has been written to $RCT_SCRIPT_OUTPUT_DIR:" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
    ls -1 "$RCT_SCRIPT_OUTPUT_DIR" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
}

and that is why when this script fails they just exit 🥲👌🏻👏🏻

@siddarthkay
Copy link
Contributor Author

Fixed by patching -X out of script_phases.sh#L107

ref : 9fb9e69

@sandipndev
Copy link

Indeed, this was a great find. Thanks for solving this. I fixed using patch-package method.
GaloyMoney/blink-mobile@f409797

I see you use nix (we use it too, via flakes) and really wish there was a way to handle Xcode inside nix dips but Apple and it's lock-in.

@siddarthkay
Copy link
Contributor Author

@sandipndev : we recently moved over to using .patch files instead with this PR -> #19451

We just don't use patch-package npm library, we apply the patches ourselves in a patch phase inside nix.

and our patch now is also pretty similar ->

- cp -R -X "$TEMP_OUTPUT_DIR/." "$RCT_SCRIPT_OUTPUT_DIR" || exit 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants