Android Emulator (AVD) fails to boot in MacOS

Viewed 1313

My android emulator fails to boot when the target platform is Level 26 (Android 8.0.0) or higher. The emulator just shows a black screen while the emulator process is constantly running at approx. 100% CPU. Note that level 25 and lower work fine.

Here's what I discovered so far:

I launched the emulator from the command-line so that I can inspect the logcat:

./emulator -avd Test2 -logcat '*:e'

Here's an excerpt from the logcat:

[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.18.91+ (android-build@wphr1.hot.corp.google.com) (gcc version 4.9 20140827 (prerelease) (GCC) ) #1 SMP PREEMPT Tue Jan 9 20:30:51 UTC 2018
[    0.000000] Command line: qemu=1 androidboot.hardware=ranchu clocksource=pit androidboot.console=ttyS0 android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=1 androidboot.logcat=*:e androidboot.selinux=permissive ndns=2 ndns=2
[    0.000000] Disabled fast string operations
... 
(skipping a few hundred lines)
...
[    1.443608] init: init first stage started!
[    1.443608] init: Using Android DT directory /proc/device-tree/firmware/android/
[    1.443608] init: First stage mount skipped (missing/incompatible fstab in device tree)
[    1.453842] init: Skipped setting INIT_AVB_VERSION (not in recovery mode)
[    1.453842] init: Loading SELinux policy
[    1.453842] selinux: SELinux:  Could not open /sepolicy:  No such file or directory
[    1.453842] 
[    1.463161] init: Failed to load monolithic SELinux policy: No such file or directory
[    1.463161] init: panic: rebooting to bootloader
[    1.463161] init: Reboot start, reason: reboot, rebootTarget: bootloader
[    1.472277] init: android::WriteStringToFile open failed: No such file or directory
[    1.472277] init: Shutdown timeout: 6
[    1.472277] init: terminating init services
[    1.472277] init: waitpid failed: No child processes
[    1.482231] init: Terminating running services took 0.013438 seconds with remaining services:0
[    1.482231] init: waitpid failed: No child processes
[    1.482231] init: vold not running, skipping vold shutdown
[    1.607664] init: powerctl_shutdown_time_ms:128:0
[    1.607664] init: Reboot ending, jumping to kernel
[    1.607664] reboot: Restarting system with command 'bootloader'
[    1.607664] reboot: machine restart
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.18.91+ (android-build@wphr1.hot.corp.google.com) (gcc version 4.9 20140827 (prerelease) (GCC) ) #1 SMP PREEMPT Tue Jan 9 20:30:51 UTC 2018
[    0.000000] Command line: qemu=1 androidboot.hardware=ranchu clocksource=pit androidboot.console=ttyS0 android.qemud=1 console=0 console=0 android.checkjni=1 qemu.gles=1 androidboot.logcat=*:e androidboot.selinux=permissive ndns=2 ndns=2
[    0.000000] Disabled fast string operations
...

This repeats infinitely every 5 seconds. So I suspect my problem has something to do with SELinux. That would make sense, since Android 8 introduced many changes in that area: https://source.android.com/security/selinux/

But I have no clue why others don't have this problem nor what to do about it.

5 Answers

I discovered it was an SELinux issue on the host. This is one way to resolve it:

sudo setsebool -P selinuxuser_execheap 1

There are more specific ways, too. But, you'll want to catch the exception to get the exact command:

Allow this access for now by executing:

ausearch -c 'qemu-system-x86' --raw | audit2allow -M my-qemusystemx86
semodule -X 300 -i my-qemusystemx86.pp

Of course, you can test in general by making SELinux temporarily permissive on your host.

After I did that, the phone display was no longer black.

Have you tried wiping data of emulator from AVD wizard?

I had same issue and got it solved by wiping emulator before launch.

enter image description here

The issue may most probably related to the GPU driver. Try to install the proper GPU driver.

It is hard to find for some GPUs. If you couldn't find one, force using software graphics as described below.

Go to virtual device settings and then Software as graphics under emulated performance section. This may significantly slow down the performance. However it will work without issues.

enter image description here

Select "Software" in the "Emulated Performance Graphics" option, in the AVD settings instead of "Automatic" or "Hardware"

Simple solution. Delete android folder. Reinstall android sdk . Delete the avd setting inside user Folders. create new AVD.

Related