Skip to content

Commit af090bd

Browse files
fix: get Xcode version correctly
In some cases NativeScript CLI fails on all iOS related commands (build, run, debug, etc.) with error: `NativeScript can only run in Xcode version 6 or greater`. This happens when user has correct Xcode version, i.e. 9 or greater, but the `head` command on their machine does not support `-n` flag. This happens when the `head` command is overwritten by some tool, so the `head` executable is not the original one used by macOS. CLI has some obsolete code to check the Xcode version AFTER it has verified it in the doctorService. Delete this code and use sysInfo's getXcodeVersion, which does not rely on `head` command.
1 parent d453726 commit af090bd

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

lib/services/ios-project-service.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const getPlatformSdkName = (forDevice: boolean): string => forDevice ? DevicePla
2828
const getConfigurationName = (release: boolean): string => release ? Configurations.Release : Configurations.Debug;
2929

3030
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
31-
private static XCODEBUILD_MIN_VERSION = "6.0";
3231
private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__";
3332
private static IOS_PLATFORM_NAME = "ios";
3433

@@ -145,11 +144,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
145144
notConfiguredEnvOptions
146145
});
147146

148-
const xcodeBuildVersion = await this.getXcodeVersion();
149-
if (helpers.versionCompare(xcodeBuildVersion, IOSProjectService.XCODEBUILD_MIN_VERSION) < 0) {
150-
this.$errors.fail("NativeScript can only run in Xcode version %s or greater", IOSProjectService.XCODEBUILD_MIN_VERSION);
151-
}
152-
153147
return {
154148
checkEnvironmentRequirementsOutput
155149
};
@@ -354,13 +348,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
354348
basicArgs.push("-xcconfig", path.join(projectRoot, projectData.projectName, BUILD_XCCONFIG_FILE_NAME));
355349
}
356350

357-
// if (this.$logger.getLevel() === "INFO") {
358-
// let xcodeBuildVersion = this.getXcodeVersion();
359-
// if (helpers.versionCompare(xcodeBuildVersion, "8.0") >= 0) {
360-
// basicArgs.push("-quiet");
361-
// }
362-
// }
363-
364351
const handler = (data: any) => {
365352
this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data);
366353
};
@@ -1238,7 +1225,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
12381225
let xcodeBuildVersion = "";
12391226

12401227
try {
1241-
xcodeBuildVersion = await this.$childProcess.exec("xcodebuild -version | head -n 1 | sed -e 's/Xcode //'");
1228+
xcodeBuildVersion = await this.$sysInfo.getXcodeVersion();
12421229
} catch (error) {
12431230
this.$errors.fail("xcodebuild execution failed. Make sure that you have latest Xcode and tools installed.");
12441231
}

test/ios-project-service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ function createTestInjector(projectPath: string, projectName: string, xcode?: IX
118118
testInjector.register("pluginsService", PluginsService);
119119
testInjector.register("androidProcessService", {});
120120
testInjector.register("processService", {});
121-
testInjector.register("sysInfo", {});
121+
testInjector.register("sysInfo", {
122+
getXcodeVersion: async () => ""
123+
});
122124
testInjector.register("pbxprojDomXcode", {});
123125
testInjector.register("xcode", xcode || {
124126
project: class {

0 commit comments

Comments
 (0)