From 565b3082860ad7093baf4055b65af4982b16b0b0 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 29 Jun 2022 11:34:54 +0200 Subject: [PATCH] fix(build/ios): prompt user for device rather than failing (#1702) --- .changeset/angry-ways-double.md | 5 +++++ .github/workflows/rnx-build.yml | 2 +- incubator/build/README.md | 20 ++++++++++++++----- incubator/build/src/platforms/ios.ts | 30 ++++++++++++++++++++++------ incubator/build/workflows/github.yml | 2 +- 5 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 .changeset/angry-ways-double.md diff --git a/.changeset/angry-ways-double.md b/.changeset/angry-ways-double.md new file mode 100644 index 000000000..0f8d23259 --- /dev/null +++ b/.changeset/angry-ways-double.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/build": patch +--- + +iOS: Prompt user for device rather than failing diff --git a/.github/workflows/rnx-build.yml b/.github/workflows/rnx-build.yml index 3512ac206..07692f95f 100644 --- a/.github/workflows/rnx-build.yml +++ b/.github/workflows/rnx-build.yml @@ -102,7 +102,7 @@ jobs: security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${RUNNER_TEMP}/${KEYCHAIN_FILE}" security import "${RUNNER_TEMP}/${CERTIFICATE_FILE}" -k "${RUNNER_TEMP}/${KEYCHAIN_FILE}" -t cert -f pkcs12 -P "${P12_PASSWORD}" -A -T '/usr/bin/codesign' -T '/usr/bin/security' - security set-key-partition-list -S apple-tool:,apple: -k ${KEYCHAIN_PASSWORD} "${RUNNER_TEMP}/${KEYCHAIN_FILE}" + security set-key-partition-list -S apple-tool:,apple: -k ${KEYCHAIN_PASSWORD} "${RUNNER_TEMP}/${KEYCHAIN_FILE}" 1> /dev/null security list-keychain -d user -s "${RUNNER_TEMP}/${KEYCHAIN_FILE}" login.keychain - name: Build iOS app run: | diff --git a/incubator/build/README.md b/incubator/build/README.md index 0341d02ec..988c0c090 100644 --- a/incubator/build/README.md +++ b/incubator/build/README.md @@ -36,11 +36,21 @@ An experimental tool for building your apps in the cloud. npm run rnx-build --platform ``` -| Flag | Description | -| :------------- | :---------------------------------------------------------------------- | -| -p, --platform | Supported platforms are `android`, `ios`, `macos`, `windows` | -| --device-type | [Optional] Supported device types are `device`, `emulator`, `simulator` | -| --project-root | [Optional] Path to the root of the project | +| Flag | Description | +| :----------------- | :---------------------------------------------------------------------- | +| `-p`, `--platform` | Supported platforms are `android`, `ios`, `macos`, `windows` | +| `--device-type` | [Optional] Supported device types are `device`, `emulator`, `simulator` | +| `--project-root` | [Optional] Path to the root of the project | + +### Android: Install Android Studio + +In order to launch the build artifact on device, you need to install Android +Studio. Once installed, go into **Preferences** ❭ **Appearance & Behavior** ❭ +**System Settings** ❭ **Android SDK**, and install **Android SDK Build-Tools** +and **Android SDK Platform-Tools**. + +If you want to run apps on the Android Emulator, follow the instructions here: +[Run apps on the Android Emulator](https://developer.android.com/studio/run/emulator). ### iOS: Install Signing Certificate and Provisioning Profile diff --git a/incubator/build/src/platforms/ios.ts b/incubator/build/src/platforms/ios.ts index 9187927b8..8dd2a951c 100644 --- a/incubator/build/src/platforms/ios.ts +++ b/incubator/build/src/platforms/ios.ts @@ -1,5 +1,6 @@ import * as os from "node:os"; import * as path from "node:path"; +import * as readline from "node:readline"; import type { Ora } from "ora"; import { untar } from "../archive"; import { retry } from "../async"; @@ -195,7 +196,14 @@ async function install(device: Device, app: string): Promise { async function launch(device: Device, app: string): Promise { const { type, udid } = device; if (type === "device") { - const launch = iosDeploy("--id", udid, "--bundle", app, "--justlaunch"); + const launch = iosDeploy( + "--id", + udid, + "--bundle", + app, + "--justlaunch", + "--noinstall" + ); const { stderr, status } = await launch; if (status !== 0) { return new Error(stderr); @@ -230,11 +238,21 @@ async function selectDevice( : (device) => device.type === "device"; const physicalDevice = devices.find(search); if (!physicalDevice) { - const message = deviceName - ? `Failed to find device: ${deviceName}` - : "Failed to find a physical device"; - spinner.fail(message); - return null; + // Device detection can sometimes be flaky. Prompt the user to make sure + // a device is properly plugged in, and try again. + const prompt = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + const device = deviceName ? `device: ${deviceName}` : "a physical device"; + await new Promise((resolve) => + prompt.question( + `Failed to find ${device} - please make sure it is properly plugged in.\n\nPress any key to try again`, + resolve + ) + ); + prompt.close(); + return selectDevice(deviceName, deviceType, spinner); } const { name, osVersion } = physicalDevice; diff --git a/incubator/build/workflows/github.yml b/incubator/build/workflows/github.yml index 3512ac206..07692f95f 100644 --- a/incubator/build/workflows/github.yml +++ b/incubator/build/workflows/github.yml @@ -102,7 +102,7 @@ jobs: security unlock-keychain -p "${KEYCHAIN_PASSWORD}" "${RUNNER_TEMP}/${KEYCHAIN_FILE}" security import "${RUNNER_TEMP}/${CERTIFICATE_FILE}" -k "${RUNNER_TEMP}/${KEYCHAIN_FILE}" -t cert -f pkcs12 -P "${P12_PASSWORD}" -A -T '/usr/bin/codesign' -T '/usr/bin/security' - security set-key-partition-list -S apple-tool:,apple: -k ${KEYCHAIN_PASSWORD} "${RUNNER_TEMP}/${KEYCHAIN_FILE}" + security set-key-partition-list -S apple-tool:,apple: -k ${KEYCHAIN_PASSWORD} "${RUNNER_TEMP}/${KEYCHAIN_FILE}" 1> /dev/null security list-keychain -d user -s "${RUNNER_TEMP}/${KEYCHAIN_FILE}" login.keychain - name: Build iOS app run: |