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

Feat: List android devices #1765

Merged

Conversation

adamTrz
Copy link
Collaborator

@adamTrz adamTrz commented Dec 5, 2022

Summary:

Similar to #1676 - list available devices and let user choose from one.

Screenshot 2022-12-05 at 11 55 08

Fetch available devices (adb device) and emulators (emulator -list-avds) and pass selection to run-android command.
If user select either physical device or booted emulator we simply call runOnSpecificDevice with selected deviceId.
Gets a bit trickier when user selects not-booted emulator. We need to launch it at known port bc we need it to pass all further avd commands (avd -s emulator-${port} [command]).

Test Plan:

Clone the fork and run run-android script with proper flag:

❯ node ../cli/packages/cli/build/bin.js run-android --list-devices

@adamTrz adamTrz marked this pull request as ready for review December 6, 2022 12:32
@adamTrz adamTrz requested a review from thymikee as a code owner December 6, 2022 12:32

const device = await listAndroidDevices();
if (!device) {
return logger.error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will exit with code 0. I think we want to throw?

Comment on lines 99 to 105
} else {
logger.error(
`Failed to launch emulator. Reason: ${chalk.dim(result.error || '')}.`,
);
logger.warn(
'Please launch an emulator manually or connect a device. Otherwise app may fail to launch.',
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw so the exit code is non-zero

Comment on lines +49 to +52
return buffer
.toString()
.replace(/\[ro\.product\.model\]:\s*\[(.*)\]/, '$1')
.trim();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extract transforming regex to a separate fn and write unit tests :)


const emulatorCommand = process.env.ANDROID_HOME
? `${process.env.ANDROID_HOME}/emulator/emulator`
: 'emulator';

const getEmulators = () => {
export const getEmulators = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider moving it to separate file to avoid unexpected circular deps and make it clearer what's shared (although one could say export says it all, and they would be right)

adamTrz and others added 3 commits December 6, 2022 16:13
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this merged 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants