如何强制 react-native 项目在物理 android 设备上运行?

时间:2021-02-12 01:50:32

标签: android react-native react-native-android

我正在尝试让我的 react-native 项目在物理 android 设备上运行。 当我运行“adb device”时,我得到了正确的输出:

List of devices attached
LMX210APMc7ea5434   device
emulator-5554   device

但是,当我运行“react-native run-android”时,我得到了这个:

react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
(node:3285) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Jetifier found 967 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
/bin/sh: /Users/eugene/Android/Sdk/platform-tools/adb: No such file or directory
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

我确实安装了 android studio,配置了 SDK,添加了 AVD 设备等...

我也通过 USB 连接设备,进入开发者模式,启用 USB 调试,运行 adb reverse 等...

我还需要什么才能在设备上运行这个项目?

1 个答案:

答案 0 :(得分:0)

通常如果我需要在物理设备上运行我的项目,我会关闭我的模拟器。它在设备上运行没有问题。您可以使用 npx react-native run-android --deviceId LMX210APMc7ea5434。 adb devices 命令的第一个值是 deviceId。