How to deploy an Expo/React Native app to iOS Device from Xcode - xcode

I'm somewhat new to react native and expo but I've been trying to deploy a test version to my phone but can't figure out how to get it to build.
For some extra context, I built most of it in Expo and then ejected it (yes I know this isn't the best choice but I liked the features Expo provided). I ejected it because I needed NFC support which isn't currently supported in Expo so I added that in manually in Xcode after I ejected.
When I open the Xcode workspace and try to deploy it to my phone I get the following error:
Error: Failed to connect to the packager server. If you did not start this build by running 'react-native run-android', you can start the packager manually by running 'react-native start' in the project directory. (Error: Request to packager server failed: 500)
    at /Users/user/Downloads/honorProj-reactNatveFinal/honorProj/reactNative/ethelontisApp/node_modules/expo-updates/scripts/createManifest.js:40:11
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Command PhaseScriptExecution failed with a nonzero exit code
I know it says run react-native start in the project directory (although I'm not entirely what the at /Users/... is refering too) but what really threw me was that it mentioned react-native run-android which doesn't seem like it should be related at all.
Lastly I'm completely and utterly lost with what Command PhaseScriptExecution is.
Thanks for the help.

I was facing the exact same issue. So I just completed the set up the android development first.
But before doing anything, follow the below steps, it may solves the problem.
Step-1: Open terminal and navigate to your project directory example: cd Your project path.
Step-2: Type npx react-native start
Step-3: If you get any error like "error listen EADDRINUSE: address already in use :::8081"
Then follow step-4 to 6:
Step-4 : type sudo lsof -n -i4TCP:8081 // You will get PID from here
Step-5: type kill -9 PIDvalue
Step-6: Repeat the step 2 and 3 once again
If you will not get any error in step- 2 then type npx react-native run-android
and check if there is any error. If yes, then you have to set up the android development first to make it working - (As of now I found this way, but not sure if anyone can find any better way).
Else Open the code using xcode then clean the build and also clean the build folder then try to run.
Thanks, Hope it will help.

Related

Command PhaseScriptExecution failed with a nonzero exit code - Xcode 13.4.1

I'm using M1 chip and xCode 13.4.1. I get the following React Native error while executing the app in the simulator:
The following build commands failed:
PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/Ibra/Library/Developer/Xcode/DerivedData/Mario-girhlsdkqiibhqhflwlyrybpo/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E110.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)
The problem persists even when I start a brand-new React Native project and try to execute it on iOS. What led to the error and how can it be fixed?
Thank you
Described answers didn't help me, but I started reading error description: and I found out that in error description on the line 2: my folder's name was written partially. Folder name consisted 2 words divided by 1 space example: "My folder" in the error was written just "My". I just changed folder's name to "MyFolder" and it helped me to fix the problem
it has multiple solutions:
to solve this run this command in terminal in ios folder , pod deintergrate and install pod with the commad pod install
Restart your Mac , it is some time due to cache, delete derived data and logs from XCode -> Prefrences and location
I faced same issue and I figured out following solutions:
What worked for me was npx react-native-clean-project and choosing y for all options, this will clean your React Native project by purging caches and modules, and reinstalling them again.
And here're some solutions that worked for others:
If you're using nvm, nvm unalias default could solve the issue.
This error could be due to Xcode can't find your node path, so try sudo ln -s $(which node) /usr/local/bin/node
Delete node_modules then cd ios && pod deintegrate then reinstall node modules and npx react-native start --reset-cache
I solve this issue with below procedure:
Keychain Access > Cetificates > Login
Find any Apple Certificate that has the blue + symbol
Change it to "Use System Defaults" and close it.
You'll see a pop up. Type in your password to update settings.
Close Keychain. Open your project, clean build files and run.
Note: Mac with M1, Xcode 14.1

CFBundleIdentifier does not exist on react-native

Easy bounty here for grabs. Does not necessarily require any react-native experience. Problem seems to be in open source code, which is available out there:
Updated xcode, and now when I try to run my react-native app by issuing following command: react-native run-ios I get an error:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
error Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier DerivedData/Build/Products/Debug-iphonesimulator/MyAppName.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
debug Error: Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier DerivedData/Build/Products/Debug-iphonesimulator/MyAppName.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnSimulator (project-root-dir/node_modules/#react-native-community/cli/build/commands/runIOS/runIOS.js:181:45)
Before those errors, the command prints out info about successful build, and that it is about to install the build:
info ** BUILD SUCCEEDED **
info Installing DerivedData/Build/Products/Debug-iphonesimulator/MyAppName.app
So it seems the build is ok, but when it tries to install the app it fails?
Think I've tried "everything" I found from other questions with this similar error message, but nothing has worked for me.
Some specs:
react-native: 0.59.10
react: 16.8.3
xcode-version: Version 12.2 (12B45b)
I know there are similar questions on stackoverflow. But since none of the solutions provided there worked for me, and I wish to get it fixed, I made this separate question.
I do not know where the Info.plist file is that it tries to find: DerivedData/Build/Products/Debug-iphonesimulator/MyAppName.app/Info.plist
Inside my ios folder, there is a folder called DerivedData, but inside that there are no folder with a name Build. So I think it might be looking from a wrong location?
UPDATE:
I've been able to pinpoint where the cli launch goes wrong:
https://github.com/react-native-community/cli/blob/ba298d9c47af522f0377325bebc6c2075d41790a/packages/platform-ios/src/commands/runIOS/index.ts#L378
If I change that line let buildPath = build/${scheme}/Build/Products/${configuration}-${device}/${appName}.app
to -> build/${scheme}/Build/Products/${configuration}-${device}/MyAppRealName.app;
Then the dev launch works nicely, there's no problem. So it seems that getting the appName goes wrong. The appName is resolved here: https://github.com/react-native-community/cli/blob/ba298d9c47af522f0377325bebc6c2075d41790a/packages/platform-ios/src/commands/runIOS/index.ts#L387
const productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec(buildOutput);
I could do a post install npm script that just sets the name of the app correct and call it a day. But that's pretty hacky way. I wonder if there's an alternative that works better? I see that the runIOS file has been updated from the version that I have quite much, but the function getProductName still remains the same. So Im not sure if updating just the cli would work, or if it would even be possible, because it might require a newer react-native version, which is not an option for me right now.
newer version of #react-native-community/cli is not working on older version react-native because in newer version they have change getProductName to getPlatformName. for more detail you can read summary of this PR
Solution
As a local workaround, patch the package by patch-package node_modules/#react-native-community/cli-platform-ios/build/commands/runIOS/index.js and edited getProductName (lines 362–365) to read:
function getProductName(buildOutput) {
const productNameMatch = /export FULL_PRODUCT_NAME\\?="?(.+).app"?$/m.exec(buildOutput);
return productNameMatch ? productNameMatch[1].replace(/(?:\\(.))/g, '$1') : null;
}
The result from react-native run-ios is:
DerivedData/Build/Products/Debug-iphonesimulator/MyAppName.app/Info.plist
The correct should be:
DerivedData/Build/Products/Debug-iphonesimulator/MyAppRealName.app/Info.plist
Then you could fix it by edit Xcode project as:
Open Product menu (status bar)
Scheme -> Edit Scheme
Under build section, add a post-action
In provide build settings from: choose target of your app
Use the script to copy wrongname.app to realname.app: cp ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app ${BUILT_PRODUCTS_DIR}/real_name.app
Or you can use symlinks instead of copying.

bin/sh: /Users/xxx(bin/xcode_backend.sh: Not a directory Command PhaseScriptExecution failed with a nonzero exit code

I had problems with the flutter_facebook_login package, more specific with the pod file when building for iOS. After some research I've updated the pod repo, removed the pod.lock file, run pod install and everything installed fine but now I get this error
bin/sh: /Users/xxx(bin/xcode_backend.sh: Not a directory Command
PhaseScriptExecution failed with a nonzero exit code
note: Using new build systemnote: Planning buildnote: Constructing build description
... and I have no idea what happens. So far I've locked and unlocked the login in the keychain access, like suggested an answer on stackoverflow, then added Flutter SDK path in User-Defined Settings, following another answer, but the issue persists.
Can anyone help me with this, please?
I've figured it out.
In Xcode Targets, Project Name (Runner in this case) Build Settings, added new build setting:
FLUTTER_ROOT and then the PATH to the flutter directory /Users/user_name/Developer/flutter/ in my case and it works fine.
Screenshot:
I've followed this answer

React Native how to change iOS bundle identifier?

I tried to change the bundle identifier in the Info.plist and the xcode itself. (in full empty project).
But for some reason I can't build it. Entry, ":CFBundleIdentifier", Does Not Exist. And what strange is that I can build it successfully in the xcode but not with the npm run ios. Any idea how to solve this?
Try the react-native-rename npm package.
npm install react-native-rename -g
On the root of your React Native project execute the following command
react-native-rename "ExampleApp" -b com.newname.newid
Check the docs > react-native-rename

Starting PalmPre2 Dev. Palm-install says: "no devices found"

I am a iPhone Developer trying to start PalmPre2 development, so I am doing as written here
I have my emulator working and running.
I have created my workspace directory
$mkdir palmWorkspace
$cd palmWorkspace
I have create my app
$ palm-generate -p "{title:'Hello World', id:com.nacho4d.hello, version:'1.0.0'}" HelloWorld
generating new_app in /Users/nacho4d/Documents/palmWorkspace/HelloWorld
I have packaged it
$ palm-package Helloworld
creating package com.nacho4d.hello_1.0.0_all.ipk in /Users/nacho4d/Documents/palmWorkspace
but now when I try to install it I get:
$ palm-install com.nacho4d.hello_1.0.0_all.ipk
palm-install: no devices found
palm-install: no device found
Even though I have the emulator running it says the same, why is that?
Thanks in advance.
Ignacio
Answer to myself:
I have realized that pal-install seems not to be as fast as expected when recognizing/finding a running emulator. I mean, if you start the emulator just before running palm-install command, this will probably fail. After a while running the same command worked as expected ;)

Resources