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

[cli] Warn user when trying to an iOS app in a incompatible device #194

Merged
merged 4 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/cli/src/commands/InstallAndLaunchApp.ts
@@ -1,4 +1,10 @@
import { Emulator, Simulator, extractAppFromLocalArchiveAsync, AppleDevice } from 'eas-shared';
import {
Emulator,
Simulator,
extractAppFromLocalArchiveAsync,
AppleDevice,
detectIOSAppType,
} from 'eas-shared';
import { Platform } from 'common-types/build/cli-commands';

import { getPlatformFromURI } from '../utils';
Expand All @@ -21,13 +27,26 @@ export async function installAndLaunchAppAsync(options: InstallAndLaunchAppAsync
}

async function installAndLaunchIOSAppAsync(appPath: string, deviceId: string) {
const appType = await detectIOSAppType(appPath);

if (await Simulator.isSimulatorAsync(deviceId)) {
if (appType === 'device') {
throw new Error(
"iOS device builds can't be installed on simulators. Either use a physical device or generate a new simulator build."
);
gabrieldonadel marked this conversation as resolved.
Show resolved Hide resolved
}

const bundleIdentifier = await Simulator.getAppBundleIdentifierAsync(appPath);
await Simulator.installAppAsync(deviceId, appPath);
await Simulator.launchAppAsync(deviceId, bundleIdentifier);
return;
}

if (appType === 'simulator') {
throw new Error(
"iOS simulator builds can't be installed on real devices. Either use a simulator or generate an internal distribution build."
);
gabrieldonadel marked this conversation as resolved.
Show resolved Hide resolved
}
const appId = await AppleDevice.getBundleIdentifierForBinaryAsync(appPath);
await AppleDevice.installOnDeviceAsync({
bundleIdentifier: appId,
Expand Down
3 changes: 2 additions & 1 deletion packages/eas-shared/src/index.ts
Expand Up @@ -3,7 +3,7 @@ import {
AppPlatform,
extractAppFromLocalArchiveAsync,
} from './download';
import { runAppOnIosSimulatorAsync, runAppOnAndroidEmulatorAsync } from './run';
import { runAppOnIosSimulatorAsync, runAppOnAndroidEmulatorAsync, detectIOSAppType } from './run';
import * as Emulator from './run/android/emulator';
import { assertExecutablesExistAsync as validateAndroidSystemRequirementsAsync } from './run/android/systemRequirements';
import AppleDevice from './run/ios/device';
Expand All @@ -21,6 +21,7 @@ export {
runAppOnAndroidEmulatorAsync,
validateAndroidSystemRequirementsAsync,
validateIOSSystemRequirementsAsync,
detectIOSAppType,
Emulator,
Simulator,
AppleDevice,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-shared/src/run/index.ts
Expand Up @@ -5,6 +5,7 @@ import * as Simulator from './ios/simulator';
import { validateSystemRequirementsAsync } from './ios/systemRequirements';
import { assertExecutablesExistAsync } from './android/systemRequirements';
import { getAptParametersAsync } from './android/aapt';
export { detectIOSAppType } from './ios/inspectApp';

export async function runAppOnIosSimulatorAsync(
appPath: string,
Expand Down
16 changes: 16 additions & 0 deletions packages/eas-shared/src/run/ios/inspectApp.ts
@@ -0,0 +1,16 @@
import path from 'path';
import fs from 'fs-extra';

import { parseBinaryPlistAsync } from '../../utils/parseBinaryPlistAsync';

export async function detectIOSAppType(appPath: string): Promise<'device' | 'simulator'> {
const builtInfoPlistPath = path.join(appPath, 'Info.plist');
if (!fs.existsSync(builtInfoPlistPath)) {
return 'device';
}

const { DTPlatformName }: { DTPlatformName: string } =
await parseBinaryPlistAsync(builtInfoPlistPath);

return DTPlatformName.includes('simulator') ? 'simulator' : 'device';
}