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

2.8k views Asked by At

I'm new to android studio. I downloaded Bumblebee and then followed the react-native quick start installation guide react-native installation

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. 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

Processor AMD Ryzen 7 PRO 5850U

wsl --status Default Distribution: Ubuntu-20.04 Default Version: 2

Windows Subsystem for Linux was last updated on 4/27/2022 WSL automatic updates are on.

Kernel version: 5.10.102.1

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

Environment Variables -> ANDROID_HOME C:\Users\UserName\AppData\Local\Android\Sdk ANDROID_ROOT same as ANDROID_HOME JAVA_HOME C\Users\UserName\Desktop
cmdline-tools\external\com\google\guava\guava\30.1-jre

1

There are 1 answers

1
arnaldo.crescente On

Inital setup

You need to install on your Windows 10 Android Studio.

Set user variable: ANDROID_HOME=C:\Users<YOUR_USER>\AppData\Local\Android\Sdk

Add to system variable PATH:

  • %ANDROID_HOME%\emulator
  • %ANDROID_HOME%\platform-tools
  • %ANDROID_HOME%\tools

Then go to your WSL2 and install:

  1. sudo apt-get install unzip
  2. get android studio Command Line Tools Only and unzip it into /home/Android
  3. install jdk 8 with sudo apt-get install openjdk-8-jdk
  4. add this to 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"
  2. run adb version && adb.exe version check if versions match

Running on emulator

  1. Start emulator run emulator -avd <YOUR_AVD_NAME> - don't close terminal window!
  2. run adb kill-server and adb -a -P 5037 nodaemon server start - don't close terminal window!
  3. run adb devices and check you device port, e.g. device port is 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.
  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.

EDITED

You can skip steps 3-6 and connect to emulator by inserting expo url manually without waiting minutes.