如何解决错误,无法启动模拟器.原因:在 React 本机中找不到模拟器作为"模拟器 -list-avds&qu



我正在为移动应用程序创建反应原生应用程序。我在构建反应本机应用程序方面是全新的。我正在使用 ubuntu 创建应用程序,并按照以下链接创建应用程序。 https://facebook.github.io/react-native/docs/getting-started .任何人都可以解决问题吗?

在以下阶段,我收到错误:

cd AwesomeProject
npx react-native run-android

我的命令行中的错误:

All-Series:~/Projects_App/AwesomeProject$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
/bin/sh: 1: adb: not found
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...
> Task :app:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
13 actionable tasks: 4 executed, 9 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-8-openjdk-amd64 contains a valid JDK installation.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
at checkExecSyncError (child_process.js:621:11)
at execFileSync (child_process.js:639:15)
at runOnAllDevices (/home/rupeevest/Projects_App/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

转到您的 react-native 项目,然后转到 android 目录并使用此名称创建一个文件

本地属性

如果您使用的是Windows,请打开文件并粘贴Android SDK路径,如下所示:

sdk.dir=C:\\Users\\UserName\\AppData\\Local\\Android\\sdk

我在这里找到了答案

运行遇到类似问题时使用的快速修复程序

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

然后确保您的模拟器已打开并再次运行react-native run-android

对我有帮助的是,在Android Studio中打开该项目,然后从旁边的模拟器下拉列表中选择模拟器后按播放按钮。

此外,如果由于某种原因模拟器引发错误,请尝试使用其他手机安装另一个模拟器。希望这对某人有所帮助!

对我来说,将 SDK 下的emulator目录放入PATH解决了这个问题。

Hello users!
I had many problems while installing 'react native's CLI Quick start',
Mainly because, This was my first attempt.
########################## Note: Linux is case sensitive  ##########################
I am an UBUNTU 22.04 user
My system now has:
[java --version]
openjdk 18.0.2-ea 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)
[npm -v]
[
9.2.0
To download:
sudo npm install -g npm@9.2.0
]
[node -v]
[
v19.2.0
]
[error]
[
emulator not found,
SDK error,
gradel related error
]
[solution worked for me)
[
[installing jdk 18]
[
Terminal:
sudo apt install openjdk-18-jre-headless
],
[Fixing Sdk path]
[
export ANDROID_SDK_ROOT=$HOME/Library/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

above line says that 'In home directory, There is folder named(Library),
Which has Android and And ANDROID FOLDER has sdk folder'

Which was wrong, in my case,
My SDK folder was in $HOME/Android/Sdk

So i changed 

export ANDROID_SDK_ROOT=$HOME/Library/Android/Sdk
================== TO ============================

export ANDROID_SDK_ROOT=$HOME/Android/Sdk

How to check if it is main error?
Type in terminal:
$HOME/Library/Android/Sdk
If Result is:
bash: /home/rambo/Library/Android/Sdk: No such file or directory
Than you too need to fix the path.


],
[Fixing watchman]
[
Watchman error came because,
It needed other things to make it work,
I fixed it with:
sudo apt install  libgflags2.2  libgoogle-glog0v5 libboost-context1.74.0 libdouble-conversion3  libsnappy1v5
sudo dpkg -i  watchmanFileName.deb 
],
]

最新更新