Skip to content

run-android-on-specific-device#9568

Closed
LearningDave wants to merge 1 commit intofacebook:masterfrom
LearningDave:feat/run-android-on-specific-device
Closed

run-android-on-specific-device#9568
LearningDave wants to merge 1 commit intofacebook:masterfrom
LearningDave:feat/run-android-on-specific-device

Conversation

@LearningDave
Copy link
Contributor

@LearningDave LearningDave commented Aug 24, 2016

Summary

At the moment the run-android command from the react-native cli does run all available devices at once. However it would be extreme useful to have the option to choose only one specific device/simulator.
Therefore i've created a new flag for the command 'run-android': --deviceIdFromList 'deviceIdFromList' in order
to install and launch apps on a specific device/simulator from the command line.

'deviceIdFromList' is the id listed on the output of the command 'adb devices'.

Tests:

I've tested my code with the following commands:
react-native run-android --deviceIdFromList "Not existing id"
react-native run-android --deviceIdFromList
react-native run-android --deviceIdFromList "id of a simulator"
react-native run-android --deviceIdFromList "id of a device"

Output:
not-existing-device
empty-flag
simulator-1
simulator-2
device-id-1
device-id-2

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @grabbou and @burgalon to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Aug 24, 2016
@LearningDave LearningDave force-pushed the feat/run-android-on-specific-device branch from ab5ff96 to 36f98ea Compare August 24, 2016 15:25
@ghost
Copy link

ghost commented Aug 24, 2016

@LearningDave updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2016
@ghost
Copy link

ghost commented Aug 24, 2016

@LearningDave updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 24, 2016
@LearningDave
Copy link
Contributor Author

@grabbou @burgalon Please take a look. This PR would make creating automated tests using react-native much easier.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 26, 2016
@mkonicek
Copy link
Contributor

mkonicek commented Sep 5, 2016

Nice! This is useful.

Looks like there is a lot of code in runAndroid.js related to this functionality:
https://github.com/facebook/react-native/blob/master/local-cli/runAndroid/runAndroid.js

e.g.:

 const cmd = process.platform.startsWith('win')
   ? 'gradlew.bat'
   : './gradlew';

Would it be possible to refactor the code? It looks like this PR adds some logic that's already in that file.

nit: Instead of --deviceIdFromList, what do you think about simple --deviceId? Does the fact that it's "from a list" add any info?

Copy link
Contributor

@mkonicek mkonicek Sep 5, 2016

Choose a reason for hiding this comment

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

Why Promise? Is the buildApk function async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, thanks for the feedback.
i called it '--deviceIdFromList' because its not the actually device id. It is just the id created by adb. -> https://developer.android.com/studio/command-line/adb.html#commandsummary
However '--deviceId' might still be better, since it is easier to use.

I will do some refactoring and remove the promise on buildApk.

@ghost
Copy link

ghost commented Sep 6, 2016

@LearningDave updated the pull request - view changes

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 6, 2016
@LearningDave
Copy link
Contributor Author

@mkonicek I've done some refactoring, changed the flag to '--deviceId' and removed the misplaced promise.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 6, 2016
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (wording): given device id (listed by running "adb devices" on the command line).

(no space after the last .)

@mkonicek mkonicek self-assigned this Sep 8, 2016
@mkonicek
Copy link
Contributor

mkonicek commented Sep 8, 2016

Thanks for refactoring this @LearningDave. It's a useful feature, it'll take me a while to review since it's quite a bit of code.

Have you run the test plan again after refactoring?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space after )

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 8, 2016
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you call adb.getDevices rather than reimplement it here?

function getDevices(): Array<string> {

@mkonicek
Copy link
Contributor

mkonicek commented Sep 8, 2016

OK I did a basic review :)

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 8, 2016
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 21, 2016
@mroswald
Copy link
Contributor

@LearningDave could you please rebase your branch against current master? thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 24, 2016
@hramos
Copy link
Contributor

hramos commented Nov 7, 2016

@LearningDave are you still planning to ship this?

Summary:
New flag for the command 'run-android': --deviceIdFromList <deviceIdFromList>
in order to install and launch apps on a specific device/simulator from the command
line.

<deviceIdFromList> is the id listed on the output of the command 'adb devices'
@LearningDave
Copy link
Contributor Author

@mroswald the branch is rebased now :)

@hramos yea i do. Sorry for the late response.

@mkonicek
Copy link
Contributor

mkonicek commented Dec 15, 2016

This is probably not the behavior we want (the user didn't specify "true"):

screenshot 2016-12-15 20 06 03

const fs = require('fs');
const isPackagerRunning = require('../util/isPackagerRunning');
const path = require('path');
const isPackagerRunning = require('../util/isPackagerRunning');
Copy link
Contributor

Choose a reason for hiding this comment

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

alphasort these please

const path = require('path');
const isPackagerRunning = require('../util/isPackagerRunning');
const Promise = require('promise');
const adb = require('./adb');
Copy link
Contributor

Choose a reason for hiding this comment

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

alphasort

adb.getDevices().map((device) => tryRunAdbReverse(device));
console.log(chalk.bold(
'Building the app...'
));
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be on single line.

});
} catch (e) {
console.log(chalk.red(
'Could not build the app on the device, read the error above for details.\n'
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not building the app on the device. We are either building the app, or installing it on device.

@mkonicek
Copy link
Contributor

Just small nits, we can fix these as a followup. Thanks for working on this!

@facebook-github-bot shipit

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Dec 15, 2016
@facebook-github-bot
Copy link
Contributor

@mkonicek has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mkonicek
Copy link
Contributor

@LearningDave are you up for sending a small followup PR for fixing the small nits above?

@mroswald
Copy link
Contributor

@LearningDave if you want I can take over the improvements PR - will ping you on mail too

command: '--flavor [string]',
description: '--flavor has been deprecated. Use --variant instead',
}, {
command: '--configuration [string]',
Copy link
Contributor

@SandroMachado SandroMachado Dec 20, 2016

Choose a reason for hiding this comment

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

Why did you removed the configuration flag? This is a breaking change.

facebook-github-bot pushed a commit that referenced this pull request Jan 2, 2017
Summary:
As mkonicek suggested in [#9568](#9568 (comment)) I did some cleanup

**Test plan (required)**

Only one functional change:
> Run `react-native run-android --deviceId`

Before it was beginning to build the app and then failing because of the missing device "true" :-)
Now it's showing a message and stopping the build:
```
❯ react-native run-android --deviceId
Starting JS server...
Parameter missing (device id)
```
Closes #11703

Differential Revision: D4376615

Pulled By: ericvicenti

fbshipit-source-id: 3c6e0f12220ab22539c7bc3d390367e02c96728a
grabbou pushed a commit to react-native-community/cli that referenced this pull request Sep 26, 2018
Summary:
At the moment the run-android command from the react-native cli does run all available devices at once. However it would be extreme useful to have the option to choose only one specific device/simulator.
Therefore i've created a new flag for the command 'run-android': --deviceIdFromList 'deviceIdFromList' in order
to install and launch apps on a specific device/simulator from the command line.

'deviceIdFromList'  is the id listed on the output of the command 'adb devices'.

I've tested my code with the following commands:
react-native run-android --deviceIdFromList "Not existing id"
react-native run-android --deviceIdFromList
react-native run-android --deviceIdFromList "id of a simulator"
react-native run-android --deviceIdFromList "id of a device"

Output:
![not-existing-device](https://cloud.githubusercontent.com/assets/9102810/17931086/d843abc8-6a09-11e6-995d-8c737dd5ed5c.png)
![empty-flag](https://cloud.githubusercontent.com/assets/9102810/17931087/d8443930-6a09-11e6-94f3-d
Closes facebook/react-native#9568

Differential Revision: D4335133

Pulled By: mkonicek

fbshipit-source-id: a827628316be1b5751225851323b1131f451574c
grabbou pushed a commit to react-native-community/cli that referenced this pull request Sep 26, 2018
Summary:
As mkonicek suggested in [#9568](facebook/react-native#9568 (comment)) I did some cleanup

**Test plan (required)**

Only one functional change:
> Run `react-native run-android --deviceId`

Before it was beginning to build the app and then failing because of the missing device "true" :-)
Now it's showing a message and stopping the build:
```
❯ react-native run-android --deviceId
Starting JS server...
Parameter missing (device id)
```
Closes facebook/react-native#11703

Differential Revision: D4376615

Pulled By: ericvicenti

fbshipit-source-id: 3c6e0f12220ab22539c7bc3d390367e02c96728a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants