15

I have built the Android source for the emulator. I read in the Android Source documentation that the path to 'emulator' is added autmatically during a successful build. However I have two questions about this:

  1. If I open a new shell or close my existing shell, 'emulator' is no longer found. Surely I don't have to build each time I want to run the emulator?

  2. If the emulator requires an AVD how do I create and manage these given there is no Android SDK on my machine?

Thanks, Jack

SOLUTION to part 2.

I needed to create an environment variable called ANDROID_PRODUCT_OUT. From the the following command:

emulator -help-build-images

I read...

The emulator detects that you are working from the Android build system by looking at the ANDROID_PRODUCT_OUT variable in your environment.

If it is defined, it should point to the product-specific directory that contains the generated system images.

I then did a search for 'system.ing' in my 'out' directory. since I am building for the emulator the image was in:

out/target/product/generic

I added the following line to my .bashrc file:

export ANDROID_PRODUCT_OUT=/home/jack.wootton/code/out/target/product/generic

I was then able to run the emulator from:

/home/jack.wootton/code/out/host/linux-x86/bin

SOLUTION to part 1.

I don't know about Android Virtual Devices, so this question still stands - however I did not need to provide one to run the emulator after doing a successful build and setting the ANDROID_PRODUCT_OUT environment variable.

Update to solutions

Apparently variables such as ANDROID_PRODUCT_OUT should be automatically created during a build and using the envSetup.sh script. I guess something has gone wrong with my environment setup for this not to happen.

1
  • Hi Jack, I am able to up single emulator without mentioning -avd but failed to up multiple emulators at a same time, facing error "ERROR: Running multiple emulators with the same AVD is an experimental feature". I am not sure how to create AVDs so that i can run multiple emulators simultaneously. (stackoverflow.com/questions/61347106/…)
    – Toral
    Apr 23, 2020 at 11:01

5 Answers 5

8

You shared that:

Apparently variables such as ANDROID_PRODUCT_OUT should be automatically created during a build and using the envSetup.sh script. I guess something has gone wrong with my environment setup for this not to happen.

I ALSO ATTEMPTED to get this to work and LEARNED that:

  1. lunch full-eng sets up all the appropriate env
  2. to check it, simply run:
    env | grep ANDROID
    and you will see all the appropriate env variables setup.
    These are local to the current shell only!
  3. emulator then does what it should.

When I came back to the shell later, I simply ran lunch full-eng again to restore my environment.
I hope this helps others as well!

1
  • +1, this solved my problem same as OP's. only thing I'll add is that coming back to a shell I would run . build/envsetup.sh then lunch full-eng, as envsetup gives additional variables and commands, most importantly the lunch command!
    – MDMoore313
    Sep 16, 2013 at 2:57
5

Just do the following:

source build/envsetup.sh or . build/envsetup.sh
setpaths

That does the trick. Make sure you run it from your source directory.

0
4

To check my built sources for emulator I've created the following script in the root folder of the project. I run it from another command line and it does not require to run all the time running . build/envsetup.sh and lunch full-eng commands. You can edit this script for your needs and if you need to run other device - simply change folder.

out/host/linux-x86/bin/emulator -sysdir out/target/product/generic/ -system out/target/product/generic/system.img -ramdisk out/target/product/generic/ramdisk.img -data out/target/product/generic/userdata.img -kernel prebuilt/android-arm/kernel/kernel-qemu -sdcard sdcard.img -skindir sdk/emulator/skins -skin WVGA800 -scale 0.7 -memory 512 -partition-size 1024
2

You can add these to your .bashrc file

export ANDROID_PRODUCT_OUT=$ANDROID_SRC/out/target/product/generic
export ANDROID_BIN=$ANDROID_SRC/out/host/linux-x86/bin
PATH=$ANDROID_BIN:$PATH
0

In fact, the program "emulator" is just a wrapper for the real emulator-qemu, such as emulator-arm or emulator-x86. The "emulator" you invoked will collect the arguments you typed in and find the proper emulator-qemu to execute.

The problem you met is that you did not explicitly describe which image/avd you want to start. You can either using the argument "@avd YOUR-AVD_NAME" or "ANDROID_PRODUCT_OUT" environment variable to set the dir where your avd is placed. BTW, avd dir contains some files to describe how this device looks like.

". build/envsetup.sh" is the script that set the environment variables for the Android build process. So it is easy to understand why "ANDROID_PRODUCT_OUT" will be set at that time. Its default value should be "PATH/TO/ANDROID/out/target/product/generic".

PS: If you want to know more, you can refer to the source file: "PATH/TO/ANDROID/external/qemu/android/main-emulator.c". You can find the emulator main there.

Not the answer you're looking for? Browse other questions tagged or ask your own question.