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

Adding Build Target and Scheme causes run-ios to fail #14907

Closed
zephinzer opened this issue Jul 8, 2017 · 1 comment
Closed

Adding Build Target and Scheme causes run-ios to fail #14907

zephinzer opened this issue Jul 8, 2017 · 1 comment
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@zephinzer
Copy link

zephinzer commented Jul 8, 2017

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

Yes

Environment

  1. react-native -v: react-native-cli: 2.0.1, react-native: 0.46.1
  2. node -v: v6.10.2
  3. npm -v: 3.10.10
  4. yarn --version (if you use Yarn): 0.24.6

Then, specify:

  1. Target Platform (e.g. iOS, Android): iOS
  2. Development Operating System (e.g. macOS Sierra, Windows 10): Mac OS X El Capitan
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): Xcode

Steps to Reproduce

  1. Create new application (react-native init rnclifail)
  2. Open rnclifail.xcodeproj in Xcode
  3. Go to Product > Manage Schemes
  4. Select rnclifail from list and click the setings icon
  5. Click duplicate
  6. Name it rnclifail2
  7. Click on rnclifail project in left side panel
  8. Right click on first Target (rnclifail) and click Duplicate
  9. Select Duplicate Only
  10. Click on the newly added Target, hit enter and change it's name from rnclifail copy to rnclifail2, and the change the bundle identifier postfix so it's rnclifail2 instead of rnclifail-copy.
  11. Add a provisioning team as required
  12. Go to Product > Manage Schemes again
  13. Click on rnclifail2 and enable Shared so it's similar to the original rnclifail
  14. Click Edit
  15. Change the Executable to rnclifail2.app
  16. Change Build Configuration to Release
  17. Go to the Terminal in the project folder and bundle the application for Release:
    react-native bundle --platform ios --dev false --bundle-output iOS/main.jsbundle --entry-file index.ios.js.
  18. Drag and drop the generated main.jsbundle and main.jsbundle.meta into the rnclifail group folder in XCode. Select Copy items if needed, select Create groups and select both rnclifail and rnclifail2 in Add to targets.
  19. Now run the application using: react-native run-ios --scheme rnclifail --configuration Debug. It should pass and install rnclifail.app which is expected behaviour. See output below.
  20. Now run the application using: react-native run-ios --scheme rnclifail2 --configuration Release. It should pass too but it installed rnclifail.app instead of rnclifail2.app. See output below.

Output from Step 19

Installing build/Build/Products/Debug-iphonesimulator/rnclifail.app
Launching org.reactjs.native.example.rnclifail
org.reactjs.native.example.rnclifail: 1063

Output from Step 20

Installing build/Build/Products/Release-iphonesimulator/rnclifail.app
Launching org.reactjs.native.example.rnclifail
org.reactjs.native.example.rnclifail: 99028

Expected Behavior

The rncliapp2.app would get deployed.

Actual Behavior

The rncliapp.app got built and deployed.

Reproducible Demo

  1. Clone the repo at https://github.com/zephinzer/rnclifail
  2. Do a yarn install
  3. Perform steps 19/20 from above Steps to Reproduce

Fix

Have analysed the build output and logs and found that the block starting at 158 in /local-cli/runIOS/runIOS.js (https://github.com/facebook/react-native/blob/master/local-cli/runIOS/runIOS.js#L158) contains the error:

The following is the current code:

buildProcess.on('close', function(code) {
  let productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec(buildOutput);
  if (productNameMatch && productNameMatch.length && productNameMatch.length > 1) {
    return resolve(productNameMatch[1]);//0 is the full match, 1 is the app name
  }
  return buildProcess.error? reject(error) : resolve();
});

Problem 1

This assumes a build output where a line exists such that:

export FULL_PRODUCT_NAME="appName.app"

exists, which does not happen to be true. The actual build output (gotten by console.log(buildOutput) shows that the line we expect is actually without the apostrophes:

export FULL_PRODUCT_NAME=appName.app

What happens is that there is no matched productNameMatch and resolve() is called which results in appName being null on line 97 (https://github.com/facebook/react-native/blob/master/local-cli/runIOS/runIOS.js#L97), and the CLI defaults to using the inferredSchemeName which is wrong.

Problem 2

The current code assumes that only one instance of export FULL_PRODUCT_NAME=<APP_NAME>.app will appear in the build output, which may not be true in a custom build scheme, however according to Xcode behaviour, we can expect the final product of each Build Scheme to be the last listed. We can fix this by not assuming any length and instead taking the last index of the matches.

Solution

The fix would be to change the block of code to the following block, which would retrieve all instances of export FULL_PRODUCT_NAME=<APP_NAME>.app and use the last one:

buildProcess.on('close', function(code) {
  const fullProductNamePattern = /export FULL_PRODUCT_NAME=?(.+).app/mg;
  const productNameMatch = [];
  let match;
  while((match = fullProductNamePattern.exec(buildOutput)) !== null) {
    productNameMatch.push(match[1]);
  }
  if (productNameMatch && productNameMatch.length && productNameMatch.length > 0) {
    const lastProductName = productNameMatch[productNameMatch.length - 1];
    return resolve(lastProductName);//0 is the full match, 1 is the app name
  }
});

Have already fixed this in my local repo so that I can get the correct files built, and will submit a PR when I can.

@hramos
Copy link
Contributor

hramos commented Sep 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos closed this as completed Sep 21, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants