React-Native run-android on specific device

后端 未结 5 423
时光说笑
时光说笑 2021-02-01 14:13

Is it possible to use the run-android command for one specific device only?

For example, if I have three devices (or emulators) connected and I want to use

相关标签:
5条回答
  • 2021-02-01 14:43

    May be we can not select which android device attached to run.

    Read from official react native website:

    You must have only one device connected at a time.

    0 讨论(0)
  • 2021-02-01 14:51

    Elaborating on @alexander 's answer, you can use the following workflow:

    cd android
    ./gradlew assembleDebug # assembleRelease for release builds
    adb install -s <yourdevice> app/build/outputs/apk/yourapk.apk # You can check the identifier for your device with adb devices
    adb reverse tcp:8081 tcp:8081 Will forward the phone's 8081 port to the computer's 8081, where the packager listens. If you are deploying over Wi-Fi, have a look at: https://facebook.github.io/react-native/docs/running-on-device-android.html#configure-your-app-to-connect-to-the-local-dev-server-via-wi-fi
    

    In a different screen, run:

    npm start # Will run the packager
    

    If you really need this, you might want to wrap the first snippet into a script that you can parametrize with your phone's identifier.

    0 讨论(0)
  • 2021-02-01 14:56

    To run react-native application on optional device you can specify some flags in run command. To see available add --help:

    react-native run-android --help

    Then you can specify your device id throught --deviceId

    react-native run-android --deviceId=DEVICE_ID

    To see available devices ids'

    adb devices

    0 讨论(0)
  • 2021-02-01 15:06

    In our experience:

    To list AVDs:

    $ANDROID_HOME/tools/emulator -list-avds

    To run a specific emulator: use the -avd flag

    $ANDROID_HOME/tools/emulator -avd Pixel_API_28_AOSP

    To run React Native in the currently-running emulator:

    react-native run-android

    To choose between multiple running emulators: (per this answer)

    adb devices
    react-native run-android --deviceId=DEVICE_ID
    
    0 讨论(0)
  • 2021-02-01 15:09

    You don't need to use run-android command to start it on specific device

    Firstly, you have to start the packager:

    ./packager/packager.sh
    

    Then just build an APK file and run it on target device. APK will connect to the build server, and fetch bundle from it automatically.

    But if it didn't happen by some reasons, click on reload button :-)

    0 讨论(0)
提交回复
热议问题