求助:执行npx react-native run-android时提示未找到模拟器,但PowerShell中可检测到运行中的AVD
Hey there! It’s super frustrating when your emulator shows up in emulator -list-avds but React Native can’t seem to detect it. Let’s walk through the most common fixes to get your app running on the emulator:
Check environment variable consistency across terminals
The terminal you’re using for React Native might not have the same environment variables as the PowerShell window whereemulator -list-avdsworks. Make sureANDROID_SDK_ROOTis set as a system environment variable (not just a user variable), and that%ANDROID_SDK_ROOT%\emulatoris added to yourPathvariable. After verifying, close all open terminals and restart them—this ensures the updated variables take effect.Verify your emulator is recognized by adb
Even if the emulator is running, it might not be connected to the Android Debug Bridge (adb). Runadb devicesin your PowerShell; if your emulator doesn’t show up here, reset adb with these commands:adb kill-server adb start-serverCheck
adb devicesagain—once your emulator appears in the list, trynpx react-native run-androidagain.Manually specify the Android SDK path for React Native
Sometimes React Native doesn’t pick up the SDK path automatically. Try running the command with the SDK root explicitly defined:npx react-native run-android --android-sdk-root="C:\Users\YourUsername\AppData\Local\Android\Sdk"Replace the path with your actual Android SDK location (you can find this in Android Studio’s SDK Manager under "SDK Location").
Avoid special characters/spaces in your AVD name
If your emulator’s name has spaces or special characters (like "My Awesome Emulator"), React Native might struggle to detect it. Rename your AVD to something simple (e.g., "MyEmulator") via Android Studio’s AVD Manager, then restart the emulator and retry the command.Restart your emulator
Occasionally emulators can enter a hung state where they’re visible inemulator -list-avdsbut unresponsive to React Native. Close the emulator completely, launch it again from Android Studio or viaemulator -avd YourAVDName, then run the React Native command once it’s fully loaded and ready.
Start with the first two fixes—they resolve most cases of this issue!
内容的提问来源于stack exchange,提问作者Qba

