Building Android from source - emulator and AVDs

Jack picture Jack · Jul 29, 2011 · Viewed 22.8k times · Source

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.

Answer

JoelParke picture JoelParke · May 26, 2012

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!