TECH
BLOG

React Native's Run-Android has different tasks performed with or without a device ID

2020
7

beginning

React Native's run-android command installs APKs on all Android devices connected to a PC.
On the other hand, if you specify the device ID with --deviceID, you can install APKs only on specific Android devices.
However, since there was a difference between Gradle tasks executed with and without device ID specified, I have summarized the results of my research.

versions

  • @react -native-community/cli-platform-android: 4.9.0

How to investigate the tasks to be performed

If you specify the --verbose option of the react-native command, you can see the command to be executed, so check it with this.

If you don't specify a device ID

$ react-native run-android --verbose
Info Running jetifier to migrate libraries to AndroidX. Can you disable it using the “--no-jetifier” flag.
Jetifier found 1041 file (s) to forward-jetify. Using 8 workers...
INFO JS SERVER ALREADY RUNNING.
Info Presents the App...
debug running command “cd android && gradlew.bat app: installDebug -preactNativeDevServerport=8081”

The app:installDebug task is running. This builds the app and installs the APK on all Android devices.

When specifying a device ID

$ react-native run-android --verbose --deviceId xxxxx
Info Running jetifier to migrate libraries to AndroidX. Can you disable it using the “--no-jetifier” flag.
Jetifier found 1391 file (s) to forward-jetify. Using 8 workers...
INFO JS SERVER ALREADY RUNNING.
INFO BUILDING THE APP...
debug running command "gradlew.bat build -x lint”

The build task is running. This performs app builds, tests, Javadoc builds, etc.
Furthermore, even if a task is specified with the --tasks option, it is not reflected, so tasks other than the build cannot be excluded.

I want to install it on a specific device with just an apk build

Currently, it is impossible to change it with options, etc., so it seems that there is only one of the following.

  • Turn off or unplug the USB cable on the Android device you don't want to install
  • Rewrite “build” in the buildAPK of node_modules/ @react -native-community/cli-platform-Android/build/commands/runAndroid/index.js to “assembleDebug”

When the following pull requests are imported, the build commands are unified and replaced by assembleDebug tasks, so it seems that they will be resolved in the future.

RELATED PROJECT

No items found.