Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Emulator (AVD) fails to boot in MacOS

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+ ([email protected]) (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+ ([email protected]) (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.

like image 469
Kris Van Bael Avatar asked Sep 01 '18 19:09

Kris Van Bael


People also ask

Why is my AVD not working?

In case you get an error like "Intel virtualization technology (vt,vt-x) is not enabled". Go to your BIOS settings and enable Hardware Virtualization. 3) Restart Android Studio and then try to start the AVD again.

Why is my AVD Manager not working?

SDK Build Tools are not installed If it fails then you may have to install it again. You look at the build tab at the bottom of the screen, it will display the error message and option to install the Build tools. Install it and you should be able to see the AVD Manager. Another way is to go to the SDK Manager.

Does Android Emulator work on Mac?

Whether it's a game, productivity app, or something else, if you're using a Mac computer, you can still get access to Android apps. All you have to do is use an Android emulator.


1 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.

like image 71
OpenStandards.net Avatar answered Sep 20 '22 01:09

OpenStandards.net