When you build the AOSP source code you can launch the emulator afterwards simply by typing "emulator" from the command prompt. However this only works because the build process has edited the path for that terminal window. If a new terminal window is created (or you reboot your machine etc.) then the emulator can no longer be executed from the command line.
I have the same problem as reported on stackoverlow, however none of the solutions posted there are working for me: How to start Android AOSP emulator on MAC
One of the solutions says this will do the trick:
. build/envsetup.sh
setpaths
However if I type emulator after running those commands I get the error
"You did not specify a virtual device name, and the system directory could not be found."
The other proposed solution is to set ANDROID_PRODUCT_OUT. Well that doesn't work for me either, I get an error saying:
"emulator: ERROR: bad config: virtual device has corrupted config.ini"
I actually do still have the original terminal window open (the one where I performed the build from) so I can echo what its ANDROID_PRODUCT_OUT is set to, which is this:
echo $ANDROID_PRODUCT_OUT
/Volumes/Lollipop/NexusPlayer/out/target/product/generic
But if I add that line to my .bash_profile as follows:
export ANDROID_PRODUCT_OUT=/Volumes/Lollipop/NexusPlayer/out/target/product/generic/
And then launch a new terminal window and then run the emulator command, thats when I get the corrupted config.ini message.
As I still have the original terminal window open I can see what its path is, and it looks like the AOSP build process has added all of the stuff below to it.
/Volumes/Lollipop/NexusPlayer/out/host/darwin-x86/bin:
/Volumes/Lollipop/NexusPlayer/prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.8/bin:
/Volumes/Lollipop/NexusPlayer/prebuilts/gcc/darwin-x86/:
/Volumes/Lollipop/NexusPlayer/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.8/bin:
/Volumes/Lollipop/NexusPlayer/development/scripts:
/Volumes/Lollipop/NexusPlayer/prebuilts/devtools/tools:
/Volumes/Lollipop/NexusPlayer/prebuilts/android-emulator/darwin-x86_64:
/opt/local/bin:
/opt/local/sbin:
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:
/usr/bin:/bin:
/usr/sbin:
/sbin:
/opt/X11/bin:
If I launch a new window and then add all of these to the path then STILL I get the error message about the config.ini being corrupted.
So how on earth can I get the emulator to launch if I have to start a new console window?