17

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.

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
Kris Van Bael
  • 2,842
  • 1
  • 18
  • 19
  • What is your AVD config? – mikejonesguy Sep 04 '18 at 19:58
  • Also, have you tried creating a new AVD from scratch? – mikejonesguy Sep 04 '18 at 19:58
  • I think others are having this problem, like [here](https://stackoverflow.com/questions/51761579/android-8selinux-could-not-open-sepolicy-no-such-file-or-directory) and it might be something with `/sepolicy`? – Stephen Sep 05 '18 at 13:42
  • Tried several AVD configs, and changing just android version makes the difference. But here's one: Device: Nexus One, Target: Android 8.0.0 - API Level 26, CPU/ABI: Google APIs Intel Atom (x86_64), Keyboard: no, Skin: Skin with dynamic hardware controls, Cameras: none, RAM: 512, Heap: 32, Storage: 200MB, Emulation: Use Host GPU – Kris Van Bael Sep 05 '18 at 20:11
  • It can be caused by the Linux driver of your graphics. Have you tried use Software Graphic (virtual device settings → Emulated Performance)? – Francis Sep 07 '18 at 06:29
  • Hi Francis, I'm on MacOS. And I tried with and without "use host GPU" to no avail. – Kris Van Bael Sep 09 '18 at 08:46
  • 1
    Just a guess, but I think it might have to do with the filesystem error you're getting _prior_ to the `/sepolicy` one (`missing/incompatible fstab in device tree`). This could explain why it can't find the `/sepolicy` file. Also, I found [this site](http://selinuxproject.org/page/NB_SEforAndroid_1#SELinux_Policy_Files) helpful re `/sepolicy`. Unfortunately, I don't know why moving to level 26 would cause this. Do you get that same message in the level <=25 logs too? – Turix Sep 09 '18 at 17:28
  • Ah ha. Now I think I understand why it changed at level 26 (Android 8.0) after skimming [this](https://source.android.com/devices/architecture/kernel/modular-kernels) (in particular, the "Mounting Partitions Early" section). – Turix Sep 10 '18 at 07:30
  • Device: Nexus One, Target: Android 8.0.0 - API Level 26, CPU/ABI: Google APIs Intel Atom (x86_64), Keyboard: no, Skin: Skin with dynamic hardware controls, Cameras: none, RAM: 512, Heap: 32, Storage: 200MB, Emulation: Use Host GPU : For this Configuration make sure, Google APIs Intel Atom (x86_64) image installed for API 26.0 and RAM should be 1GB And Above and min Storage should be 512 MB. – Aniruddh Parihar Sep 10 '18 at 08:03
  • You might try disabling SELinux, as well as looking at the kernel startup messages, like: `./emulator -avd Test2 -logcat '*:e' -selinux disabled -show-kernel` – Turix Sep 10 '18 at 08:11
  • @KrisVanBael I have exactly the same problem but on Windows 7 using eclipse. Have you fond the solution? I see that none of the answers is accepted. – Viktor Brešan Jan 16 '19 at 21:30
  • @viktor. No solution. In the end I had to go buy an android 8 device to get my software tested. – Kris Van Bael Jan 17 '19 at 22:12

5 Answers5

1

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.

  • In the meantime I ported my project to AndroidStudio and did a clean install on all SDK's folders. Since I'm not able to check your answer, you get the benefit of the doubt. – Kris Van Bael Sep 02 '19 at 22:41
0

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

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
0

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

Bertram Gilfoyle
  • 9,899
  • 6
  • 42
  • 67
0

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

ygngy
  • 3,630
  • 2
  • 18
  • 29
0

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

Jin Thakur
  • 2,711
  • 18
  • 15
  • I tried it, but it still didn't work. I am getting more and more convinced that it is plain impossible to develop for Android 9 on Eclipse. In the meantime Google even took the eclipse downloads offline. – Kris Van Bael Sep 02 '19 at 22:42
  • try running as admin through terminal or command prompt.It takes time for first time. – Jin Thakur Sep 03 '19 at 12:58