Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native ios build succeeds but path to app bundle is wrong

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
like image 740
shotofcode Avatar asked Nov 28 '19 06:11

shotofcode


1 Answers

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)

enter image description here

and Xcode > Preferences > Locations > Advanced

enter image description here

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.

like image 173
Alexandre GUIDET Avatar answered Oct 26 '22 16:10

Alexandre GUIDET