in src/extension/appLauncher.ts [229:409]
public async launch(launchArgs: any): Promise<any> {
const mobilePlatformOptions = this.requestSetup(launchArgs);
// We add the parameter if it's defined (adapter crashes otherwise)
if (!isNullOrUndefined(launchArgs.logCatArguments)) {
mobilePlatformOptions.logCatArguments = [
this.parseLogCatArguments(launchArgs.logCatArguments),
];
}
if (!isNullOrUndefined(launchArgs.variant)) {
mobilePlatformOptions.variant = launchArgs.variant;
}
if (!isNullOrUndefined(launchArgs.scheme)) {
mobilePlatformOptions.scheme = launchArgs.scheme;
}
if (!isNullOrUndefined(launchArgs.productName)) {
mobilePlatformOptions.productName = launchArgs.productName;
}
if (!isNullOrUndefined(launchArgs.launchActivity)) {
mobilePlatformOptions.debugLaunchActivity = launchArgs.launchActivity;
}
const platformDeps: MobilePlatformDeps = {
packager: this.packager,
projectObserver: this.projectObserver,
};
this.mobilePlatform = new PlatformResolver().resolveMobilePlatform(
launchArgs.platform,
mobilePlatformOptions,
platformDeps,
);
let extProps: any = {
platform: {
value: launchArgs.platform,
isPii: false,
},
};
if (mobilePlatformOptions.isDirect) {
extProps.isDirect = {
value: true,
isPii: false,
};
}
try {
const versions =
await ProjectVersionHelper.getReactNativePackageVersionsFromNodeModules(
mobilePlatformOptions.nodeModulesRoot,
ProjectVersionHelper.generateAdditionalPackagesToCheckByPlatform(launchArgs),
);
mobilePlatformOptions.reactNativeVersions = versions;
extProps = TelemetryHelper.addPlatformPropertiesToTelemetryProperties(
launchArgs,
versions,
extProps,
);
await TelemetryHelper.generate("launch", extProps, async generator => {
try {
if (this.mobilePlatform instanceof GeneralMobilePlatform) {
generator.step("resolveMobileTarget");
await this.resolveAndSaveMobileTarget(launchArgs, this.mobilePlatform);
}
await this.mobilePlatform.beforeStartPackager();
generator.step("checkPlatformCompatibility");
TargetPlatformHelper.checkTargetPlatformSupport(mobilePlatformOptions.platform);
generator.step("startPackager");
await this.mobilePlatform.startPackager();
// We've seen that if we don't prewarm the bundle cache, the app fails on the first attempt to connect to the debugger logic
// and the user needs to Reload JS manually. We prewarm it to prevent that issue
generator.step("prewarmBundleCache");
this.logger.info(
localize(
"PrewarmingBundleCache",
"Prewarming bundle cache. This may take a while ...",
),
);
await this.mobilePlatform.prewarmBundleCache();
generator
.step("mobilePlatform.runApp")
.add("target", mobilePlatformOptions.target, false);
this.logger.info(
localize(
"BuildingAndRunningApplication",
"Building and running application.",
),
);
await this.mobilePlatform.runApp();
if (mobilePlatformOptions.isDirect) {
if (launchArgs.useHermesEngine) {
generator.step("mobilePlatform.enableHermesDebuggingMode");
if (mobilePlatformOptions.enableDebug) {
this.logger.info(
localize(
"PrepareHermesDebugging",
"Prepare Hermes debugging (experimental)",
),
);
} else {
this.logger.info(
localize(
"PrepareHermesLaunch",
"Prepare Hermes launch (experimental)",
),
);
}
} else if (launchArgs.platform === PlatformType.iOS) {
generator.step("mobilePlatform.enableIosDirectDebuggingMode");
if (mobilePlatformOptions.enableDebug) {
this.logger.info(
localize(
"PrepareDirectIosDebugging",
"Prepare direct iOS debugging (experimental)",
),
);
} else {
this.logger.info(
localize(
"PrepareDirectIosLaunch",
"Prepare direct iOS launch (experimental)",
),
);
}
}
generator.step("mobilePlatform.disableJSDebuggingMode");
this.logger.info(localize("DisableJSDebugging", "Disable JS Debugging"));
await this.mobilePlatform.disableJSDebuggingMode();
} else {
generator.step("mobilePlatform.enableJSDebuggingMode");
this.logger.info(localize("EnableJSDebugging", "Enable JS Debugging"));
await this.mobilePlatform.enableJSDebuggingMode();
}
} catch (error) {
if (
!mobilePlatformOptions.enableDebug &&
launchArgs.platform === PlatformType.iOS &&
launchArgs.type === DEBUG_TYPES.REACT_NATIVE
) {
// If we disable debugging mode for iOS scenarios, we'll we ignore the error and run the 'run-ios' command anyway,
// since the error doesn't affects an application launch process
return;
}
generator.addError(error);
this.logger.error(error);
throw error;
}
});
} catch (error) {
if (error && error.errorCode) {
if (error.errorCode === InternalErrorCode.ReactNativePackageIsNotInstalled) {
TelemetryHelper.sendErrorEvent(
"ReactNativePackageIsNotInstalled",
ErrorHelper.getInternalError(
InternalErrorCode.ReactNativePackageIsNotInstalled,
),
);
} else if (error.errorCode === InternalErrorCode.ReactNativeWindowsIsNotInstalled) {
TelemetryHelper.sendErrorEvent(
"ReactNativeWindowsPackageIsNotInstalled",
ErrorHelper.getInternalError(
InternalErrorCode.ReactNativeWindowsIsNotInstalled,
),
);
}
}
this.logger.error(error);
throw error;
}
}