I have been facing an issue where 'react-native run-ios' can not start, regardless of the simulator I add to the --simulator argument.
XCode has the correct location for the 'command line tools'
I am always getting the error:
Could not find iPhone X simulator
Error: Could not find iPhone X simulator
at resolve (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/eric/.../swim/node_modules/react-native/local-cli/cliEntry.js:117:22)
react-native info
> React Native Environment Info:
> System:
> OS: macOS 10.14.2
> CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU # 2.90GHz
> Memory: 6.76 GB / 32.00 GB
> Shell: 3.2.57 - /bin/bash
> Binaries:
> Node: 10.15.0 - /usr/local/bin/node
> Yarn: 1.13.0 - /usr/local/bin/yarn
> npm: 6.4.1 - /usr/local/bin/npm
> SDKs:
> iOS SDK:
> Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
> IDEs:
> Android Studio: 3.1 AI-173.4819257
> Xcode: 10.1/10B61 - /usr/bin/xcodebuild
> npmPackages:
> react: 16.6.3 => 16.6.3
> react-native: 0.57.8 => 0.57.8
> npmGlobalPackages:
> create-react-native-app: 1.0.0
> react-native-cli: 2.0.1
> react-native-git-upgrade: 0.2.7
Update
It is fixed in v1.9.8.
Update cli is the easy solution
npm install -g react-native-cli#latest
This issue is fixed but not released yet.
https://github.com/react-native-community/react-native-cli/pull/274
So it can be solved temporarily to fix the file below.
/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
Change this line
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
to
if (!version.includes('iOS') && !version.includes('tvOS')) {
Do not forget apply this again when you reinstall packages.
I've found a temporary fix:
In the following file:
/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
...change line 42 to:
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('tvOS')) {
I tried like below
Open Xcode. Then Preferences -> Select Components in Tabs.
Then install any one(or more) of the available simulators on the list. Preferably the recent one at the top.
It solves the problem.
Try this script from Terminal
sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
Now run
react-native run-ios
Just do
npm install
Then it will show warnings, then fix them by using following command
npm audit fix
Here is additional temporary fix too. I am using Catalina.
I this file:
/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
Change line 42 to:
if (!version.includes('iOS') && !version.includes('tvOS')) {
Change line 52-53 from:
simulator.availability !== '(available)' &&
simulator.isAvailable !== 'YES'
to:
simulator.isAvailable !== true
because the returned json list from command xcrun simctl list --json devices, the property isAvailable is boolean and didn't have property 'availability'.
Just modify the findMatchingSimulator.js in node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js.
First boot a Simulator then run xcrun simctl list --json devices and search the one with "state" : "Booted",.
Then add at the top in the findMatchingSimulator function:
return {
udid: <uuid from booted device>, // 'BFA2D7D0-AD49-472F-8279-585DDBBF9151'
name: <Name of the booted simulator>, //"iPhone X"
booted: true,
version: "com.apple.CoreSimulator.SimRuntime.iOS-13-1",
}
I solved it by replacing line number 62 in YourProjectFolder/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
This line
if (
simulator.availability !== '(available)' &&
simulator.isAvailable !== 'YES'
) {
With this one
if (
!simulator.isAvailable
) {
In some case there may be some different solutions for everyone just debug findMatchingSimulator.js file by putting console.log() so you'll know why it is not detecting simulator. In my case the xcrun simctl list devices --json command not providing simulator.availability and simulator.isAvailable is not string it's bool.
I printed the simulator list which command is returning through the following line
console.log(JSON.stringify(simulator.simulatorName));
console.log(simulator.isAvailable);
console.log('-------------------------------------------------------------');
The after running command react-native run-ios --simulator="iPhone SE" I got output in the terminal and fixed code according to console print. And my simulator was running.
try npm install --force if you don't want to break your app with npm audit fix
Related
Description
How to fix this error. I have created simple project with latest version and when try to build the project via Xcode it generate error?
Version
0.67.3
Output of npx react-native info
OS: macOS 11.5.2
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU # 2.80GHz
Memory: 83.30 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.18.2 - /usr/local/opt/node#14/bin/node
Yarn: 1.22.15 - /usr/local/bin/yarn
npm: 6.14.15 - /usr/local/opt/node#14/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK: Not Found
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7583922
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 15.0.2 - /usr/bin/javac
npmPackages:
#react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.3 => 0.67.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
Please init new react native project with command and try to build the project in the xcode after pod install
after each time pod-install => clean build XCode > Product > Clean Build Folder(command + shift + k) => rebuild, that work.
The problem is with rn > 0.67.0, pod-cache pointing to the old file.
https://github.com/facebook/react-native/commit/01856633a1d42ed3b26e7cc93a007d7948e1f76e
You could create that into the library source or you could avoid it and use the same UIColor option just above it.
I removed:
( [RCTConvert UIColor:options.cancelButtonTintColor() ? #( options.cancelButtonTintColor()) : nil];* )
and replace it with:
( *[RCTConvert UIColor:options.tintColor() ? #(options.tintColor()) : nil]; )
my line now looks like:
UIColor *cancelButtonTintColor =
[RCTConvert UIColor:options.tintColor() ? #(*options.tintColor()) : nil];
it is not the better way, but you can do it in the meanwhile this is fixed.
clean build folder after pod install worked for me
in top navigation bar click on Production ---> Clean Build Folder
When I run react-native run-ios build succeeds and created build folder under ios. But after build, when installation starts, get the below error. The project runs successfully when I run it through xcode. What I observed is that path beginning 'DerivedData' is wrong. Instead it should be 'build'. When I rename my 'build' folder to 'DerivedData' and re-run 'react-native run-ios' the whole process completes successfully but of course with the previous build.
How can I change the 'DerivedData' to 'build'?
This error occurred immediately after I upgraded from 0.59.9 to 0.60.0.
Error:
info Installing "DerivedData/Build/Products/Debug-iphonesimulator/mobileappname.app"
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/mobileappname.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
. Run CLI with --verbose flag for more details.
Error: Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier DerivedData/Build/Products/Debug-iphonesimulator/mobileappname.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 (/Users/armaneker/WebstormProjects/mobileappname/node_modules/#react-native-community/cli-platform-ios/build/commands/runIOS/index.js:189:45)
at process._tickCallback (internal/process/next_tick.js:68:7)
React Native version:
System:
OS: macOS 10.15
Binaries:
Node: 10.15.3 - /usr/local/bin/node
npm: 6.13.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
Xcode: 11.0/11A420a - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.60.0 => 0.60.0
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Steps To Reproduce
used rn-diff-purge to upgrade from 0.59.9 to 0.60.0
android worked correctly
react-native run-ios build succeeded but installation of
app failed
The solution is not obvious, react-native-cli is trying to guess what xcode build configuration is currently setup on your computer which is what is happening on the function getBuildPath()
function getBuildPath(configuration, appName, isDevice, scheme) {
let device;
if (isDevice) {
device = 'iphoneos';
} else if (appName.toLowerCase().includes('tvos')) {
device = 'appletvsimulator';
} else {
device = 'iphonesimulator';
}
let buildPath = `build/${scheme}/Build/Products/${configuration}-${device}/${appName}.app`; // Check wether app file exist, sometimes `-derivedDataPath` option of `xcodebuild` not works as expected.
if (!_fs().default.existsSync(_path().default.join(buildPath))) {
return `DerivedData/Build/Products/${configuration}-${device}/${appName}.app`;
}
return buildPath;
}
The trick is not to patch this file, but to first setup your xcode configuration correctly Xcode > Preferences > Locations (see picture)
and Xcode > Preferences > Locations > Advanced
Once this is done, you have to cleanup your build folder, otherwise, react-native-cli will still assume that xcode is not behaving as expected, which will keep on producing the same error.
cd ios && rm -rf build
you can now execute npx react-native run-ios and everything should be fine again.
It took me quite some time to figure this out, I think that react-native-cli should output more details on what is going on under the hood for people not to be blocked.
Problem solved. I had to edit a file inside #react-native-community.
If anyone else has the same problem solution is below.
File location:
-> file:
-> node_modules
-> #react-native-community
-> cli-platform-ios
-> build
-> commands
-> runIOS
-> index.js line 314
Change:DerivedData/Build/Products/${configuration}-${device}/${appName}.app
To:build/Build/Products/${configuration}-${device}/${appName}.app
Cheers.
Anyone else getting this since upgrading from Xcode 10.3 to Xcode 11 when running react-native run-ios and any idea to get back up and running?
CoreData: annotation: Failed to load optimized model at path '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel 9.0.omo'
error Could not find iPhone X simulator
I remember this happening before and amending:
node_modules ▸ #react-native-community ▸ cli ▸ build ▸ commands ▸ runIOS ▸ findMatchingSimulator.js
As a current workaround, updating:
if (simulator.availability !== '(available)' && simulator.isAvailable !== 'YES') {
continue;
}
To:
if (simulator.availability !== '(available)' && simulator.isAvailable !== true) {
continue;
}
Seems to get me back up and running.
Hopefully this gets updated pronto.
"react-native": "^0.59.3"
Xcode 11 can't see iPhoneX or Other Simulator
- First need to add new Simulator
- Then click on the bottom left of the Simulator then choose device you wanna add 😎
Open xcode and go to window > Device and Simulators... go to the Simulators tab and click the + in the bottom left, here you can add iphone X.
You can change the default simulator to use.
react-native run-ios --simulator="iPhone 11 Pro Max"
The problem is that you are using a #react-native/cli version that doesn't detect XCode 11 simulators. You can either downgrade your XCode or install a #react-native/cli that supports it.
If you are not managing the version of #react-native/cli directly in your package.json you can simply remove your package-lock.json or yarn.lock file and install it again:
rm yarn.lock
yarn install
or
rm package-lock.json
npm install
I upgraded to Xcode 10.2 today, since upgrading I can't run react-native run-ios through the cli:
react-native run-ios --simulator="iPhone X"
Found Xcode workspace a.xcworkspace
Could not find iPhone X simulator
Error: Could not find iPhone X simulator
at resolve (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/cliEntry.js:117:22)
If I run xcrun simctl list devices all of the simulators show (Shutdown) (unavailable, runtime profile not found):
iPhone X (7AADFA50-7B57-4A40-8434-9A86F345D7ED) (Shutdown) (unavailable, runtime profile not found)
Has anyone else had this issue with RN since upgrading xcode to 10.2? It still works through Xcode.. but that means opening Xcode.
I solved like this ;
Firstly, you need to go this path
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
and then;
You need to change this code
if (!version.startsWith('iOS') && !version.startsWith('tvOS'))
with
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS'))
I hope, it will be helpful,
ref : https://github.com/facebook/react-native/issues/21498#issuecomment-476621627
I thought I would add my solution here too, in hopes to help someone. I just upgraded to Mac OS Mojave and I also upgraded to Xcode 10.2. My whole react native project broke, real bad. So then I downgraded Xcode back to 10.1. Then, I started to see this error, in said after running react-native run-ios:
Could not find iPhone X simulator
the above "hack" fixed it by editing the findMatchingSimulator.js file with the updates above.
Then, react-native run-ios got farther, next error was:
:CFBundleIdentifier, does not exist
I fixed this by:
cd node_modules/react-native/third-party/glog* TabEnter
./configure
Now react-native run-ios works . I hope this helps someone, this was a pain in the #ss.
This bug has been fixed since RN v0.58.0, see commits here
IIRC this bug was introduced in Xcode 10.1
Also, you can fix this by simply replacing startsWith() with includes(). But doing this every time you update node_modules is less than ideal so I would recommend updating your RN version if possible.
if could not found simulator still persists after replacing following lines of code in runSimulator.js.
Path for runSimulator.js -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }
with this one
if ( !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS') ) { continue; }
comment following lines after replacing
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
and 2nd approach after updating to XCode 11
Xcode 11 xcrun returns true or false and not YES or NO for isAvailable property as before. You can check that using the following command
xcrun simctl list devices --json
above command will print all available devices like following
com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
{
"state" : "Booted",
"isAvailable" : true,
"name" : "iPhone X",
"udid" : "E53748D1-628B-4A99-A419-4D7AE7CE4745"
}
]
Replace YES with true in the following code
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
like this
if ( simulator.availability !== '(available)' && simulator.isAvailable !== true ) { continue; }
You even just do something like this
if (version.indexOf('iOS') === -1)...
After I added shared_preferences to pubspec.yaml, iOS sumulator never success to build.
I tried
flutter clean
upgrade cocoapods
pod install
pod uninstall
pod deintegrate
But none of them resolved this problem.
versions
~/i/fissus ❯❯❯ flutter --version master ✱
Flutter 0.10.1-pre.45 • channel master • https://github.com/flutter/flutter.git
Framework • revision bdc3dda5f2 (2 days ago) • 2018-10-15 15:03:02 -0700
Engine • revision 32f417db0d
Tools • Dart 2.1.0-dev.7.1.flutter-b99bcfd309
~/i/fissus ❯❯❯ dart --version master ✱
Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on "macos_x64"
~/i/fissus ❯❯❯ pod --version master ✱
1.5.3
pubspec.yaml
name: fproject
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
rxdart: ^0.19.0
cupertino_icons: ^0.1.2
font_awesome_flutter: ^8.1.0
http: ^0.12.0
shared_preferences: ^0.4.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
fonts:
- family: Noto
fonts:
- asset: fonts/NotoSansCJKjp-Regular.otf
- asset: fonts/NotoSansCJKjp-Bold.otf
error message
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
ERROR: Invalid version /Users/ryu.ishikawa/issus/fissus/ios/./Podfile.lock
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
Could not build the application for the simulator.
Error launching application on iPhone XS Max.
Exited (sigterm)
memo
I've read this issue, but I cannot resolve this.
https://github.com/flutter/flutter/issues/10089
Sorry, this problem is not caused by Flutter.
GVM(a version management tool of go) overrides diff command.
So, diff "${PODS_PODFILE_DIR_PATH}/Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null always failed.
$ cd /Users/#{your_user_name}/Library/Developer/Xcode/DerivedData/Runner-{some_hash}/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build
# there are some .sh file. one of them.
$ cat Script-527F3B8B313E5250A155F99B.sh
#!/bin/sh
diff "${PODS_PODFILE_DIR_PATH}/Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
if [ $? != 0 ] ; then
# print error to STDERR
echo "error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation." >&2
exit 1
fi
# This output is used by Xcode 'outputs' to avoid re-running this script phase.
echo "SUCCESS" > "${SCRIPT_OUTPUT_FILE_0}"
to fix
configure .zshrc or so on to use default diff command.