Launching the Android Emulator from the Command Line

I’m not sure which update exactly broke it, but recently I got this when trying to launch the Android Emulator from the CLI:

$ emulator -list-avds
Nexus_5X_API_25

$ emulator -avd Nexus_5X_API_25
[140735953220544]:ERROR:./android/qt/qt_setup.cpp:28:Qt library not found at ../emulator/lib64/qt/lib
Could not launch '../emulator/qemu/darwin-x86_64/qemu-system-i386': No such file or directory

Apparently there’s some relative path linking happening, which of course fails when running the emulator command from a project directory.

The fix is to run the emulator command from the directory in which it resides. Some command combinations later, this is the result (with Nexus_5X_API_25 being the name of the created virtual device):

cd $(dirname $(which emulator)) && ./emulator -avd Nexus_5X_API_25

UPDATE 2017-11-28: As mentioned by Piotr in the comments below, another way to fix it, is to include the path of the emulator binary in your $PATH environment variable.

If installed correctly, you will most likely find some references to $ANDROID_HOME in your .bash_profile. Below that block, add this line to it:

export PATH="$ANDROID_HOME/emulator:$PATH"
Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Unless noted otherwise, the contents of this post are licensed under the Creative Commons Attribution 4.0 License and code samples are licensed under the MIT License

Join the Conversation

9 Comments

  1. .bash_profile

    ANDROID_HOME=/Users/you/Library/Android/sdk
    PATH=$ANDROID_HOME/platform-tools:$PATH
    PATH=$ANDROID_HOME/tools:$PATH
    PATH=$ANDROID_HOME/tools/bin:$PATH
    PATH=$ANDROID_HOME/emulator:$PATH

    The last line solves this problem for me.

    1. Hi Piotr,

      Thanks for this suggestion. It indeed works. I have updated the post with the information you’ve provided here.

      Regards,
      Bramus.

    2. Preference>Appearances &behavior >system settings>Android SDK
      You will find “SDK Tools” on the right .
      Make sure the option–“Android Emulator” has been installed already, then choose it and Apply it.

  2. Hi,
    I’m on MacOs. My Android Emulator was working till today. I now have the same qt lib error as you.
    I have added the line :
    export PATH=”$ANDROID_HOME/emulator:$PATH”
    to my .bash_profile.

    It fixes this issue but I then have another issue:

    emulator -avd Nexus_5X_API_23_2
    createImpl: failed to create context (EGL_NO_CONTEXT result)

    By chance, do you know this issue?
    Thanks

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.