I followed the official guide on how to build Android from source. The build itself proceeds without a hiccup, but I am unable to run the result in emulator.
The guide suggests after a successful build I just need to launch the emulator. I guess the environmental variables set during the preparation process ought to guarantee the emulator knows where to look. Sadly I end up with complaints about missing kernel file.
emulator: ERROR: bad workspace: cannot find prebuilt ranchu kernel in: /home/jzaruba/aosp/prebuilts/qemu-kernel/arm/ranchu/kernel-qemu
emulator: ERROR: This AVD's configuration is missing a kernel file! Please ensure the file "kernel-ranchu" is in the same location as your system image.
emulator: ERROR: ANDROID_SDK_ROOT is defined (/home/jzaruba/aosp/sdk) but cannot find kernel file in /home/jzaruba/aosp/sdk/system-images/ sub directories
So apparently I need to set ANDROID_SDK_ROOT. I played with that a bit, tried to set it to all sorts of dark places...
emulator: ERROR: ANDROID_SDK_ROOT is defined (~/aosp/development/ndk) but cannot find kernel file in ~/aosp/development/ndk/system-images/ sub directories
So now that damn thing is boldly lying to me! There are bunch of kernel-ranchu files in those subdirectories:
My understanding is a different (non-production) kernel has to be used with the emulator. So I tried the -kernel option, pointed to all those above, one by one.
For the ones with "arm" in the path I get a dead emulator GUI (waited for tens of minutes, in case it was merely very slow)... The rest gave a fatal error causing the emulator to crash instantly:
qemu: fatal: Trying to execute code outside RAM or ROM at 0x00000004
How do I provide the proper kernel file please?
I googled and stackoverflowed like crazy. During last couple of days I started several times from the scratch, on a clean machine.
I tried Ubuntu 15 and 16, both as VM and also as a regular installation. I am building aosp_deb-userdebug (Nexus 7  w/ GSM), android-6.0.1_r55