Skip to content

Commit ca7cbde

Browse files
SandroMachadoFacebook Github Bot
authored andcommitted
Add the scheme configuration option to the run-ios command
Summary: With the current `run-ios` script it is not possible to create/run iOS release builds or any other kind of scheme configuration from the terminal (we need to use `Xcode`). The reason for this is that the `run-ios` script does not expose the scheme configuration option for the `xcodebuild` command. This PR exposes that property and allows the developers to directly create/run release builds from the terminal. This PR also closes [this](https://productpains.com/post/react-native/create-ios-release-builds-from-terminal) request at `productpains`. And answers to [this](http://stackoverflow.com/questions/40303229/run-a-react-native-ios-release-build-from-terminal) question at the `stackoverflow`. **Test plan (required)** To generate a release build just run: ``` sh react-native run-ios --configuration Release ``` The output ``` sh Found Xcode project App.xcodeproj Launching iPhone 6 (iOS 9.3)... Building using "xcodebuild -project App.xcodeproj -scheme App -destination id=B0738993-CE4A-4D Closes #10637 Differential Revision: D4151793 Pulled By: cpojer fbshipit-source-id: 5a0fcdd59589977f3e251ec9bb3ba85e8919cffc
1 parent 4785a60 commit ca7cbde

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

docs/RunningOnDevice.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ Building an app for distribution in the App Store requires using the `Release` s
206206

207207
Apps built for `Release` will automatically disable the in-app Developer menu, which will prevent your users from inadvertently accessing the menu in production. It will also load the JavaScript locally, so you can put the app on a device and test whilst not connected to the computer.
208208

209+
> Hint
210+
>
211+
> You can also use the `React Native CLI` to perform this operation using the option `--configuration` with the value `Release` (e.g. `react-native run-ios --configuration Release`).
212+
209213
Once built for release, you'll be able to distribute the app to beta testers and submit the app to the App Store.
210214

211215
### App Transport Security

local-cli/runIOS/runIOS.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const path = require('path');
1414
const findXcodeProject = require('./findXcodeProject');
1515
const parseIOSDevicesList = require('./parseIOSDevicesList');
1616
const findMatchingSimulator = require('./findMatchingSimulator');
17+
const getBuildPath = function(configuration = 'Debug', appName, isDevice) {
18+
return `build/Build/Products/${configuration}-${isDevice ? 'iphoneos' : 'iphonesimulator'}/${appName}.app`;
19+
};
1720

1821
function runIOS(argv, config, args) {
1922
process.chdir(args.projectPath);
@@ -31,7 +34,7 @@ function runIOS(argv, config, args) {
3134
if (args.device) {
3235
const selectedDevice = matchingDevice(devices, args.device);
3336
if (selectedDevice){
34-
return runOnDevice(selectedDevice, scheme, xcodeProject);
37+
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration);
3538
} else {
3639
if (devices){
3740
console.log('Could not find device with the name: "' + args.device + '".');
@@ -42,19 +45,19 @@ function runIOS(argv, config, args) {
4245
}
4346
}
4447
} else if (args.udid) {
45-
return runOnDeviceByUdid(args.udid, scheme, xcodeProject, devices);
48+
return runOnDeviceByUdid(args, scheme, xcodeProject, devices);
4649
} else {
4750
return runOnSimulator(xcodeProject, args, inferredSchemeName, scheme);
4851
}
4952
}
5053

51-
function runOnDeviceByUdid(udid, scheme, xcodeProject, devices) {
52-
const selectedDevice = matchingDeviceByUdid(devices, udid);
54+
function runOnDeviceByUdid(args, scheme, xcodeProject, devices) {
55+
const selectedDevice = matchingDeviceByUdid(devices, args.udid);
5356
if (selectedDevice){
54-
return runOnDevice(selectedDevice, scheme, xcodeProject);
57+
return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration);
5558
} else {
5659
if (devices){
57-
console.log('Could not find device with the udid: "' + udid + '".');
60+
console.log('Could not find device with the udid: "' + args.udid + '".');
5861
console.log('Choose one of the following:');
5962
printFoundDevices(devices);
6063
} else {
@@ -88,12 +91,12 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
8891
}
8992
resolve(selectedSimulator.udid)
9093
})
91-
.then((udid) => buildProject(xcodeProject, udid, scheme))
94+
.then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration))
9295
.then((appName) => {
9396
if (!appName) {
9497
appName = inferredSchemeName;
9598
}
96-
const appPath = `build/Build/Products/Debug-iphonesimulator/${appName}.app`;
99+
let appPath = getBuildPath(args.configuration, appName);
97100
console.log(`Installing ${appPath}`);
98101
child_process.spawnSync('xcrun', ['simctl', 'install', 'booted', appPath], {stdio: 'inherit'});
99102

@@ -108,14 +111,14 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
108111
})
109112
}
110113

111-
function runOnDevice(selectedDevice, scheme, xcodeProject){
112-
return buildProject(xcodeProject, selectedDevice.udid, scheme)
114+
function runOnDevice(selectedDevice, scheme, xcodeProject, configuration){
115+
return buildProject(xcodeProject, selectedDevice.udid, scheme, configuration)
113116
.then((appName) => {
114117
if (!appName) {
115118
appName = scheme;
116119
}
117120
const iosDeployInstallArgs = [
118-
'--bundle', 'build/Build/Products/Debug-iphoneos/' + appName + '.app',
121+
'--bundle', getBuildPath(configuration, appName, true),
119122
'--id' , selectedDevice.udid,
120123
'--justlaunch'
121124
];
@@ -132,11 +135,12 @@ function runOnDevice(selectedDevice, scheme, xcodeProject){
132135
});
133136
}
134137

135-
function buildProject(xcodeProject, udid, scheme) {
138+
function buildProject(xcodeProject, udid, scheme, configuration = 'Debug') {
136139
return new Promise((resolve,reject) =>
137140
{
138-
const xcodebuildArgs = [
141+
var xcodebuildArgs = [
139142
xcodeProject.isWorkspace ? '-workspace' : '-project', xcodeProject.name,
143+
'-configuration', configuration,
140144
'-scheme', scheme,
141145
'-destination', `id=${udid}`,
142146
'-derivedDataPath', 'build',
@@ -162,21 +166,19 @@ function buildProject(xcodeProject, udid, scheme) {
162166
});
163167
}
164168

165-
166169
function matchingDevice(devices, deviceName) {
167170
if (deviceName === true && devices.length === 1)
168171
{
169172
console.log(`Using first available device ${devices[0].name} due to lack of name supplied.`)
170173
return devices[0];
171-
}
174+
}
172175
for (let i = devices.length - 1; i >= 0; i--) {
173176
if (devices[i].name === deviceName || formattedDeviceName(devices[i]) === deviceName) {
174177
return devices[i];
175178
}
176179
}
177180
}
178181

179-
180182
function matchingDeviceByUdid(devices, udid) {
181183
for (let i = devices.length - 1; i >= 0; i--) {
182184
if (devices[i].udid === udid) {
@@ -217,7 +219,10 @@ module.exports = {
217219
command: '--simulator [string]',
218220
description: 'Explicitly set simulator to use',
219221
default: 'iPhone 6',
220-
}, {
222+
} , {
223+
command: '--configuration [string]',
224+
description: 'Explicitly set the scheme configuration to use',
225+
} , {
221226
command: '--scheme [string]',
222227
description: 'Explicitly set Xcode scheme to use',
223228
}, {

0 commit comments

Comments
 (0)