简体   繁体   English

修复 Android Studio React-Native WSL 不会启动模拟器并出现更多错误

[英]fix Android Studio React-Native WSL won't launch emulator with more errors

I'm new to android studio.我是 android 工作室的新手。 I downloaded Bumblebee and then followed the react-native quick start installation guide react-native installation我下载了 Bumblebee 然后按照 react-native 快速入门安装指南react-native 安装

I will open Android studio and within the terminal run npx react-native init MyApp, cd MyApp, npx react-native start, npx react-native run-android.我将打开 Android 工作室并在终端中运行 npx react-native init MyApp, cd MyApp, npx react-native start, npx ZB0DF5BC3BAE30D491ZB0DF5BC3BAE30D4911 run I get the errors:我得到错误:

error Failed to launch emulator. Reason: No emulators found as an output of 'emulator -list-avds'

Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version. Class name for the included build object: org.gradle.composite.internal.DefaultIncludedBuild$IncludedBuildImpl_Decorated.
6 actionable tasks: 4 executed, 2 up-to-date
Note: /mnt/c/Users/RandallTaylor/Mobile/App3/node_modu


* What went wrong:
Could not determine the dependencies of task ":app:compileDebugJavaWithJavac".
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at "/mnt/c/Users/RandallTaylor/Mobile/App3/android/local.properties" 
   / note local.properties exists. I attempted with the linux and windows path version as SDK manager points to the Microsoft OS where it exits. and still get this error /

I've spent two days on this reading stack overflow thread with no progress.我在这个阅读堆栈溢出线程上花了两天时间,没有任何进展。 Any advice would be appreciated.任何意见,将不胜感激。

SetUp and local system info:设置和本地系统信息:

Windows 10 Windows 10

Processor AMD Ryzen 7 PRO 5850U处理器 AMD 锐龙 7 PRO 5850U

wsl --status Default Distribution: Ubuntu-20.04 Default Version: 2 wsl --status 默认发行版:Ubuntu-20.04 默认版本:2

Windows Subsystem for Linux was last updated on 4/27/2022 WSL automatic updates are on. Linux 的 Windows 子系统上次更新时间为 2022 年 4 月 27 日 WSL 自动更新已开启。

Kernel version: 5.10.102.1 Kernel 版本:5.10.102.1

Android Studio Bubblebee Android Studio Bubblebee

SDK manager -> SDK Platorms -> Android 11.0R with Android SDK Platform 30, Source for Android 30, Intel x86 Aton Sytem Image SDK Tools -> 30.0.2 installed SDK manager -> SDK Platorms -> Android 11.0R with Android SDK Platform 30, Source for Android 30, Intel x86 Aton Sytem Image SDK Tools -> 30.0.2 installed

Environment Variables -> ANDROID_HOME C:\Users\UserName\AppData\Local\Android\Sdk ANDROID_ROOT same as ANDROID_HOME JAVA_HOME C\Users\UserName\Desktop环境变量 -> ANDROID_HOME C:\Users\UserName\AppData\Local\Android\Sdk ANDROID_ROOT 与 ANDROID_HOME JAVA_HOME C\Users\UserName\Desktop 相同
cmdline-tools\external\com\google\guava\guava\30.1-jre cmdline-tools\external\com\google\guava\guava\30.1-jre

Inital setup初始设置

You need to install on your Windows 10 Android Studio.您需要在 Windows 10 Android Studio 上安装。

Set user variable: ANDROID_HOME=C:\Users<YOUR_USER>\AppData\Local\Android\Sdk设置用户变量:ANDROID_HOME=C:\Users<YOUR_USER>\AppData\Local\Android\Sdk

Add to system variable PATH:添加到系统变量PATH:

  • %ANDROID_HOME%\emulator %ANDROID_HOME%\模拟器
  • %ANDROID_HOME%\platform-tools %ANDROID_HOME%\平台工具
  • %ANDROID_HOME%\tools %ANDROID_HOME%\工具

Then go to your WSL2 and install:然后 go 到您的 WSL2 并安装:

  1. sudo apt-get install unzip
  2. get android studio Command Line Tools Only and unzip it into /home/Android仅获取 android studio 命令行工具并将其解压缩到 /home/Android
  3. install jdk 8 with sudo apt-get install openjdk-8-jdk使用sudo apt-get install openjdk-8-jdk安装 jdk 8
  4. add this to your.bashrc/.zshrc:将此添加到 your.bashrc/.zshrc:
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
export ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037

export ANDROID_HOME=$HOME/Android
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
  1. restart bash and run sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"重启 bash 并运行sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
  2. run adb version && adb.exe version check if versions match运行adb version && adb.exe version检查版本是否匹配

Running on emulator在模拟器上运行

  1. Start emulator run emulator -avd <YOUR_AVD_NAME> - don't close terminal window启动模拟器运行emulator -avd <YOUR_AVD_NAME> - 不要关闭终端 window
  2. run adb kill-server and adb -a -P 5037 nodaemon server start - don't close terminal window运行adb kill-serveradb -a -P 5037 nodaemon server start - 不要关闭终端 window
  3. run adb devices and check you device port, eg device port is 5554.运行adb devices并检查您的设备端口,例如设备端口是 5554。
  4. form your wsl terminal run socat -d -d TCP-LISTEN:5554,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5554 , to install socat sudo apt-get install socat ,形成你的wsl终端运行socat -d -d TCP-LISTEN:5554,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5554 ,安装socat sudo apt-get install socat
  5. you should be all set up now.你现在应该都准备好了。
  6. run yarn start inside project folder and then click 'a' to run android emulator, it takes me about 4-5 minutes.在项目文件夹中运行yarn start然后单击“a”运行 android 仿真器,大约需要 4-5 分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于Android的react-native和Visual Studio Emulator - react-native and Visual Studio Emulator for Android React本机开发人员菜单不会在Android Studio模拟器上显示 - React native developer menu won't show on Android Studio emulator React Native Android Studio Emulator 启动问题 - React Native Android Studio Emulator launch issue 反应原生的Android Studio模拟器热重载 - Android Studio emulator hot reload for react-native 在 mac 上为 react-native 环境的模拟器安装 android studio 时出现问题 - Problem with install android studio for emulator for react-native environment on mac 在Android模拟器上运行react-native项目不起作用 - Running react-native project on Android emulator doesn't work 无法在 react-native 故事书的 android 模拟器上看到故事 - Can't see stories on android emulator for react-native storybook 无法在模拟器上运行 react-native android(Androidx 问题) - Can't run react-native android on emulator (Androidx problem) 无法启动模拟器。 原因:模拟器在启动前退出 en React Native when react-native run-android - Failed to launch emulator. Reason: Emulator exited before boot en React Native when react-native run-android Android Studio无法“反应 - 原生启动”,如何解决? - Android Studio can not 'react-native start', How to fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM