152

I am new to Android Studio and I am having problems while using the emulator. When I try to run it keeps crashing saying:

"Cannot launch AVD in emulator" [6816]:ERROR:./android/qt/qt_setup.cpp:28:Qt library not found at C:\Users\Jay\AppData\Local\Android\Sdk\emulator\lib64\qt\lib

Could not launch 'C:\Users\Jay\AppData\Local\Android\Sdk\emulator/qemu/windows-x86_64/qemu-system-i386.exe': No such file or directory

I have enabled VT-x from BIOS settings yet I am having the problem. I have searched a lot and cannot find an answer. Any help will be much appreciated. Can anyone give me a solution?

Screenshot of error Log Snapshot

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
Jay
  • 1,521
  • 2
  • 9
  • 4

33 Answers33

173

This seems to be an issue relating to the recent update. A temporary solution is to launch emulator from within the /path/to/android-sdk/tools directory in the commandline.

See https://code.google.com/p/android/issues/detail?id=235461 to follow the issue.

mixel
  • 25,177
  • 13
  • 126
  • 165
Vuong Pham
  • 1,852
  • 1
  • 8
  • 6
105

All other answers did not work for me as "Android Emulator" was not installed with a standard installation of Android Studio. Make sure you have installed it and then try other answers if required.enter image description here

Akshar Patel
  • 8,998
  • 6
  • 35
  • 50
  • 2
    Installing "Android Emulator" also fixed it for me. After that I was able to launch the emulator again, but got following HAXM error "unknown hax vcpu return 1". Simply restarting my machine finally solved all problems. (See: https://stackoverflow.com/a/41867405/2350644) – ice_chrysler May 31 '17 at 09:16
  • 2
    installing emulator from inside the Android Studio worked for me as well. Now I can run Emulator from the command line as well. – abhinavgoyal02 Jul 22 '17 at 08:52
  • 3
    Really thank you, solved my problem after wasting 3 hours :( – Hossam Ghareeb Jul 24 '17 at 14:16
  • 1
    I had the problem of starting emulator on Mac. It used to crash after startup without any message. Your tip helped me. – Rostyslav Roshak Aug 11 '17 at 15:41
  • 1
    Fixed my issue ,Thanx :) – Ramkesh Yadav Nov 01 '17 at 12:40
  • 3
    This helped me too. Basically with my fresh install of Android Studio, after running updates and trying to start an image in the emulator the first time. This was the error. And yeah, it's pretty logical you need to have the emulator installed if you want to use it. Would be nice if Android Studio just says: "you want to run a virtual device on the emulator we provide, but you need to install this emulator first, do you want to install it now?".... – morksinaanab Jan 04 '18 at 03:34
  • 1
    Can a moderator mark this as accepted please, too many unhelpful comments are stopping people from reaching this comment. Helped me out after multiple hours, websites and coffee. Thanks – Tom Nijs Jul 11 '18 at 22:52
  • Could you please edit your answer to include adding path to the emulator as well? if you are running it from the command line it needs to be there. – Hades Feb 07 '19 at 01:38
  • 1
    This saved me. Thanks a lot Akshar :) – Parth Patel Apr 09 '19 at 16:34
88

For Linux or Mac systems you can add the following to ~/.profile (or ~/.bashrc):

function emulator { cd "$(dirname "$(which emulator)")" && ./emulator "$@"; }

then run to load the changes:

source ~/.profile

(or source ~/.bashrc of course)

This will allow to execute emulator until they fix the issue

(based on #10 yanokwa comment from https://code.google.com/p/android/issues/detail?id=235461)

J. Costa
  • 7,442
  • 4
  • 26
  • 31
  • tried this with SDK Tools 25.3.1 and ubuntu 16.10 and it did not work, started getting libGL errors – vallllll Mar 23 '17 at 09:14
  • i used `which emulator` in osx to find the folder – V-SHY Mar 23 '17 at 09:45
  • @vallllll I've only tested on Mac but it should work on Linux too. Are you able to run within Android Studio? – J. Costa Mar 23 '17 at 11:02
  • @J.Costa no from android studio does not run at all, no error displayed either, but the answer from Cillian Myles to add -use-system-libs works for me. Probably on ubuntu some open gl libraries are not present and that is why it works on mac but not ubuntu. – vallllll Mar 23 '17 at 11:55
  • 8
    In zsh use `whence -p` instead of `which`. Also put `cd ... && ...` in parentheses to execute them in subshell to avoid changing directory in the current shell. – mixel Apr 13 '17 at 18:02
  • Hi @J. Costa, I voted you answer because it's work fine here, but you can tell me how I can get more system resource, because my computer loose improvement and turn very fast when the avd is lunching – Armando Marques da S Sobrinho May 28 '17 at 11:31
  • 12
    I can confirm that it works on linux and zsh with @mixel's modifications: `function emulator { ( cd "$(dirname "$(whence -p emulator)")" && ./emulator "$@"; ) }` – Andy Jones Jun 29 '17 at 09:23
  • Also works on Mac but the function should be defined in `~/.bash_profile` instead. – Derek 朕會功夫 Sep 18 '17 at 23:48
  • And slightly modified solution for those freaks, who install android sdk via Homebrew, hence have symlink to emulator: ```function emulator { cd "$(dirname $(readlink "$(which emulator)"))" && ./emulator "$@" &>/dev/null & disown; }``` – Sofa Dec 15 '17 at 17:01
77

I've installed the latest Android Emulator 26.1.2 which has solved this problem.

Btw if in your PATH you have both of this:

  • C:\AndroidSDK\tools

  • C:\AndroidSDK\emulator

The emulator command will try to use the emulator.exe inside the tools folder, which is not working.

To solve this in your PATH you need to move C:\AndroidSDK\emulator in the line before the tools directory, in this way the emulator executable will be searched inside the emulator folder first and will take precedence over the one present in the tools folder

MacOS: If you have a Mac you can move ~/Library/Android/sdk/emulator before ~/Library/Android/sdk/tools

MatPag
  • 41,742
  • 14
  • 105
  • 114
22

a simple solution is to add this alias to your .bashrc .profile or equivalent

alias emu="$ANDROID_HOME/tools/emulator"

then source .bashrc or .profile or just simply open a new terminal

finally running your emulator will be as simple as emu -avd name

Amine Hakkou
  • 554
  • 5
  • 14
  • 2
    +1 for the alias, which solved it for me. I don't have ANDROID_HOME defined though, so just replaced the normal path. Not sure why it seems like most have it and I don't...I'm on mac. – TahoeWolverine Aug 09 '17 at 22:39
  • to add ANDROID_HOME to your path environment first open android studio and go to "File" -> "Project Structure..." -> "SDK Location" -> "Android SDK Location" and get the sdk path e.g.: "/Library/Android/sdk/" and add the following to .zshrc: export ANDROID_HOME="/Library/Android/sdk/" – Rayon Nunes Dec 26 '22 at 03:50
13

Zsh users can add:

function emulator { ( cd "$(dirname "$(whence -p emulator)")" && ./emulator "$@"; ) }

to .zshrc (or .zshenv).

Load changes to current shell by sourcing changed file:

source ~/.zshrc

Now you can use emulator command in zsh.

Thanks to J. Costa for his answer for bash.

mixel
  • 25,177
  • 13
  • 126
  • 165
10

I had same problem with latest Android Studio installed just yesterday on Macbook.

Though the emulator binary was available in the sdk/tools folder, Android Emulator package wasn't installed. Selecting Android Emulator in Android Studio->Preferences->System Settings->Android SDK, downloaded the emulator package and installed it.

After the emulator installation, I am able to launch the emulator.

Kumar
  • 111
  • 8
7

First of all, the issue thread on Google Issue Tracker was already resolved. You don't have to set environment variable like LD_LIBRARY_PATH as a workaround any more. But you have to upgrade your Android SDK and use the LATEST emulator package (binaries). Without having that, you'll still see the annoying QT errors.

Then, it's crucial to make sure that the required SDK packages are installed to launch an emulator. When installing a specific emulator image by sdkmanager, it won't check or ask you to install required dependencies. Whenever you see error complains about ANDROID_SDK_ROOT, such as PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT or PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value, it's exactly because of that.

So the 3 other essential dependencies apart from the emulator image are:

  • platform-tools
  • platforms;android-<api_level>
  • emulator

Which you can install via:

sdkmanager "platform-tools" "platforms;android-<api_level>" "emulator"

The api_level is the same API level your emulator image is.

Jing Li
  • 14,547
  • 7
  • 57
  • 69
  • mhh i get `PANIC: Missing emulator engine program for 'x86' CPU.` also to where should the `SDK_ROOT` point? just `ANDROID_HOME`? – kemuri Jun 05 '19 at 09:02
  • i just found out `emulator` sits now in `sdk/emulator` and the one from tool causes that error. – kemuri Jun 05 '19 at 09:08
5

For those who are still experiencing the issue even when performing the command from .../Sdk/tools directory, try adding the -use-system-libs argument.

So it should be in the following format:

path/to/Sdk/emulator -use-system-libs -avd [AVD-NAME]

For me, here is an example:

/home/cillian/Android/Sdk/emulator -use-system-libs -avd Nexus5

Cillian Myles
  • 696
  • 8
  • 16
  • 2
    tested this on my ubuntu 16.10 and it is the only thing that works, I am just using emulator -use-system-libs -avd Pixel_XL_API_25. – vallllll Mar 23 '17 at 09:21
5

I had the same problem and I solved it by installing the emulator cause somehow the updates seem to have deleted it. Do that from Android Studio tools-> SDK manager. Hope this helps

nkoroi
  • 93
  • 6
  • The reinstall of the emulator from SDK Manager fixed the Qt bug, but I ended up getting another problem with HAX then. Using Mac. – Gennon Mar 24 '17 at 21:49
  • Fixed the HAX problem by quiting Docker on my machine. Have to start the emulator from the tools directory. Or else I get the Qt bug again. – Gennon Mar 24 '17 at 21:56
5

I see that you should only add below into the path to be able to launch emulator

C:\Users\Ram\AppData\Local\Android\Sdk\platform-tools
C:\Users\Ram\AppData\Local\Android\Sdk\emulator.

After installing Android Studio 3.0 and higher, I see that C:\Users\Ram\AppData\Local\Android\Sdk\emulator emulator_folder has same files as C:\Users\Ram\AppData\Local\Android\Sdk\tools tools_folder

The tools folder is missing some files, so remove the tools folder from path.

You can use below emulator commands to launch emulator from command prompt:

emulator -list-avds

emulator @Pixel_2_XL_API_26 - Based on the avd that you have setup

emulator_commands

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Ram Sharma
  • 2,487
  • 1
  • 8
  • 7
4

I have installed Android Studio 2.3.3 (today 2017-08-01) on windows 10 x64

Same issue.

  • I have manually installed emulator from Android Studio -> Tools -> Android -> Sdk Manager -> SDK Tools -> Android Emulator (version 26.1.2)

  • After installation ... same issue

  • I have added my path from emulator folder to my environments variables before tools path (like as one answer above) but still same issue.
  • Then I have deleted emulator.exe and emulator-check.exe from tools folder and this solved for mi the issue

MTK
  • 3,300
  • 2
  • 33
  • 49
4

Follow these steps to resolve that problem (Windows 10):

  1. Check in Android studio if you installed Android emulator, if not, install it.

  2. Check in Android studio if you installed Intel x86 Emulator Accelerator (HAXM installer), if not, install it.

  3. In Environment variables => System variables edit "Path". You need to add this line for emulator: %ANDROID_HOME%\emulator before %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools (The third step was a solution for me.)

4

It seems I was having same problems with emulator in tools folder and AS 4.1.1. A quick solution that I've found for Mac users to work with the new emulator of the emulator folder is to specify the whole path to it:

 ~/Library/Android/sdk/emulator/emulator <device> <flags> 
marcRDZ
  • 281
  • 2
  • 8
4

I added the following to my ~/.zshrc file and it worked. (M1 Pro Macbook)

export ANDROID_HOME=/Users/$USER/Library/Android/sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
export PATH=$ANDROID_HOME/emulator:$PATH

Remember to do source ~/.zshrc after editing it.

Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113
3

For Mac

If have create emulators, try this shell code:

#!/bin/bash
cd /Users/***/Library/Android/sdk/tools/
avds=`emulator -list-avds`
echo "show All emulators"
i=0
for item in $avds
do
    echo [$i] $item
    let i+=1
done
read index
avds=($avds)
# echo ${avds[$index]}
emulator -avd ${avds[$index]}

*** is your user name

3

This problem seems to be fixed in Cordova version 7.0.X

If you are using Cordova version 6.5.0 you can fix it easily.

The root of the problem is in the emulator.js file located from the root of your project directory at ./platforms/android/cordova/lib/emulator.js

Simply update the following line, (for me it was line 205):

.spawn('emulator', args, { stdio: 'inherit', detached: true})

to

.spawn('emulator', args, { stdio: 'inherit', detached: true, cwd: process.env['ANDROID_HOME'] + '/tools'})

This will fix the relative path issue your are experiencing.

Also, there is a second fix needed for the Cordova version 6.5.0 on line 56. Simply drop the letter "s" from the word "avds" plural, to make it "avd" singular.

Andre F
  • 423
  • 4
  • 11
  • Just to add that to others reading this is: if you have just installed the SDK via brew cash you should replace ANDROID_HOME with ANDROID_SDK_ROOT (unless you have setup the env ANDROID_HOME too) – Lubricin Aug 08 '17 at 12:08
3

I was facing this issue

  java.io.IOException: Cannot download 
 'https://dl.google.com/android/repository/emulator-windows-4266726.zip'

I updated to studio 3.0 in windows 10, my emulators stopped working.Things I did for fixing,

Deleted previous installation folders of android studio like 2.0 and 2.1 present under my username alongside .AndroidStudio3.0 folder(leaving it untouched).

Deleted previously installed emulators which any way stopped working.

Downloaded the emulator zip file manually from the link above. Pasted its contents in emulator folder of

       C:\Users\myusername\AppData\Local\Android\Sdk\emulator

Created a new emulator and started it, Bingo! it is working!!

Learner_Programmer
  • 1,259
  • 1
  • 13
  • 38
  • 1
    This is the one that finally did the trick for me, except I didn't download from the link but updated the emulator using SDK Manager in Android Studio 3.0 – yvesmancera Dec 21 '17 at 17:01
3

I was trying on Mac and facing the similar challenge. Mistakes I was doing, is adding PATH before to ANDROID_HOME which should be come at the end. Below is my zshrc file which worked.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
export ANDROID_HOME="/Users/rohitmandiwal/Library/Android/sdk"
export PATH=$ANDROID_HOME/emulator:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
Rohit Mandiwal
  • 10,258
  • 5
  • 70
  • 83
2

My android studio is in the windows operating system. but most of the answers in this page do not work for me.

but I figure it out with an easy way.

In your android studio IDE, open the [Sdk manager], check if you have downloaded the [Android Emulator] and [Android SDK tool]

How to check them?

[SDK Manager] -> [Appearance & behavior] -> [System Setting] -> [Android Sdk] -> There are tabs here and choose the second one [SDK tools]. then check [Android Emulator] and [Android SDK tool].

Hope that it can help you.

Good luck!

oscarz
  • 1,184
  • 11
  • 19
2

I just solved this issue for headless emulator scenario So If I checked my andrdoid_sdk folder there are 2 executable emulator. The issue is sitting one the version

${ANDROID_HOME}/emulator/emulator
version 29.3.4
no issue

and the second one is

${ANDROID_HOME}/tools/emulator
version 26.0.3
QT issue

so make sure you're using latest emulator version especially if you need headless emulator as stated on : https://androidstudio.googleblog.com/2019/02/emulator-2818-canary.html

surga
  • 1,436
  • 21
  • 25
2

cd $ANDROID_HOME/tools then emulator --avd @whatever_name_it_is

1

Installing Android emulator will solve the issue as this setting is not by default enabled in android studio. In android studio 3+ onwards you cannot find it under Tools-->Android-->Sdk Manager -> SDK Tools -> Android Emulator  but it's under File-->Settings-->Appearance &Behavior-->System Settings-->Android SDK-->SDK Tools-->Android Emulator

MD5
  • 1,356
  • 15
  • 14
1

A solution that worked for me that I've not seen here before is to link android-sdk/emulator/emulator to android-sdk/tools/emulator.

Dumb? Genius? worksforme.

0atman
  • 3,298
  • 4
  • 30
  • 46
1

I manage to solve this error. In my system varible i need to set ANDROID_HOME

system variable

For my User variable i need both these path

C:\Users\tonyhudson\AppData\Local\Android\Sdk\platform-tools
C:\Users\tonyhudson\AppData\Local\Android\Sdk\emulator

Remember to delete C:\Users\tonyhudson\AppData\Local\Android\Sdk\tools because it will cause the error

user variable

Tony Ngo
  • 19,166
  • 4
  • 38
  • 60
1

When you have installed only Android SDK and not Android studio. You need to find out the path of the emulator and execute with full path. For example,

/usr/local/share/android-sdk/tools/emulator @test

This should resolve your problem. At least this is what worked for me.

0

My problem turned out to be that I was running VirtualBox at the same time as the emulator. For anybody else running into this problem, have a look here: Android emulator and virtualbox cannot run at same time. Hopefully one of the answers will give you a working solution.

zwessels
  • 617
  • 1
  • 10
  • 25
0

You can also just open the Tools > AVD Manager from Android Studio and start the emulator manually.

ThinkDigital
  • 3,189
  • 4
  • 26
  • 34
  • I thought the OP _was_ about failing via the Android Studio menus. For me, the GUI works, but I can't get the command-line `emulator -avd "Nexus_5X_API_27"` to work. – MarkHu May 09 '19 at 02:24
0

There can be the bugs / updates happened in the underlying OS. So, instead of updating in .profile, /etc/environment, or .bashrc file to point adb, emulator etc, put (copy and paste) all the emulator folder inside /usr/bin directory. This /usr/bin is by default pointed by the system. Install adb tool from the terminal. This should solve everything.

And/Or, update your all environment variables in /etc/bash.bashrc file. Note that: /etc/bash.bashrc file is what gets executed everytime you open the bash terminal.

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64
0

If you're using a Docker container which is running a Ubuntu x86 image, it may not be possible to run an x86-based emulator within the Docker image. You will either get the "Qt library not found" error or the "Please ensure KVM is properly installed and usable" error (more info here).

An alternative is to use an ARM-based emulator, which are easier to run, although they are slower:

# Download an ARM emulator image
android-sdk/tools/bin/sdkmanager "system-images;android-24;default;armeabi-v7a"

# Create an ARM-based emulator AVD with 250 MB SD card
avdmanager create avd -n Android_7.0_API_24 -k "system-images;android-24;default;armeabi-v7a" -c 250M --force

# Check the image is properly created and available to run
android-sdk/emulator/emulator -list-avds

# Run the emulator
android-sdk/emulator/emulator -avd Android_7.0_API_24

More info: https://medium.com/@AndreSand/android-emulator-on-docker-container-f20c49b129ef

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
0

I am working on react-native and I was facing this problem, I couldn't open Emulator from cmd that was really annoying because I had to open it from Android Studio which is very time taking.

So, first check if you can open emulator by running cmd in Android\Sdk\emulator folder or Android\Sdk\tools if its working in any of these folder then this solution is for you!

in my case running cmd in both these folders was working but if open cmd on any other folder my emulator wont work and through this error:

[14684]:ERROR:android/android-emu/android/qt/qt_setup.cpp:28:Qt library not found at ..\emulator\lib64\qt\lib
Could not launch 'C:\Users\Shehr\AppData\Local\..\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe': No such file or directory

So how I solved it without wasting my time:

  1. first copy the path of the folder where emulator is working in cmd, in my case it was Android\Sdk\emulator && Android\Sdk\tools so we copy any one of these paths !
  2. Edit system environment variables and add new variable, write your copied path into the value and name it "EMULATOR" (or whatever you want to name the variable).

Now just run the command in cmd in any folder like this %EMULATOR% -avd DEVICE_NAME so as we named our variable EMULATOR so we will be using %EMULATOR% instead of emulator! That's how the cmd will target to the correct emulator.exe file and it will work.

halfer
  • 19,824
  • 17
  • 99
  • 186
Kashan Haider
  • 1,036
  • 1
  • 13
  • 23
0

I fixed it simply with adding $ANDROID_SDK_ROOT/emulator in $PATH.

I don't know why there are two emulator exec binary in Android SDK. 1) in $ANDROID_SDK_ROOT/tools 2) $ANDROID_SDK_ROOT/emulator, but the second one is worked for me.

I'm using fish shell adding below line in ~/.config/fish/config.fish.

set -x ANDROID_SDK_ROOT $HOME/Android/Sdk
set -x JAVA_HOME $HOME/android-studio/jre
set -x PATH $PATH $ANDROID_SDK_ROOT/emulator
set -x PATH $PATH $ANDROID_SDK_ROOT/tools
set -x PATH $PATH $ANDROID_SDK_ROOT/tools/bin
set -x PATH $PATH $ANDROID_SDK_ROOT/platform-tools
mununki
  • 350
  • 4
  • 16
0

Obviously the emulator is not installed, this could happen if you installed Android SDK using third party framework. It can installed easily using command line.

Assuming the tools folder is C:\Android\android-sdk\tools (windows) then the command to install emulator is:

C:\Android\android-sdk\tools> sdkmanager --install emulator
Dharman
  • 30,962
  • 25
  • 85
  • 135