Search code examples
androidandroid-emulatorandroid-sourcefedoraandroid-virtual-device

Trouble starting AOSP Emulator with a local AOSP build on Fedora


I am interested in starting the AOSP Emulator after successfully building it locally from scratch on my Fedora Linux 35 machine. The machine has a NVIDIA graphics card.

I followed instructions from https://source.android.com/docs/setup/start to get the latest AOSP source code. No changes were made to the source code. Then I followed instructions from https://source.android.com/docs/setup/create/avd to build the Android Emulator.

$ source build/envsetup.sh 
$ lunch sdk_phone_x86
============================================
PLATFORM_VERSION_CODENAME=UpsideDownCake
PLATFORM_VERSION=UpsideDownCake
TARGET_PRODUCT=sdk_phone_x86
TARGET_BUILD_VARIANT=eng
TARGET_ARCH=x86
TARGET_ARCH_VARIANT=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.18.16-100.fc35.x86_64-x86_64-Fedora-Linux-35-(Workstation-    Edition)
HOST_CROSS_OS=windows
BUILD_ID=AOSP.MASTER
OUT_DIR=out
============================================

$ m
#### build completed successfully ####

$ emulator

The first time running emulator, I was able to see the UI for the Emulator bringup briefly before crashing with these logs:

INFO    | Android emulator version 31.3.9.0 (build_id 9070145) (CL:N/A)
INFO    | Storing crashdata in: /tmp/.../emu-crash.db, detection is enabled
[591835:591837:20221230,121506.939761:ERROR directory_reader_posix.cc:42] opendir /tmp/.../emu-crash.db/attachments/xyz: No such file or directory (2)
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
[591835:591837:20221230,121506.968340:ERROR http_transport_socket.cc:169] SSL_connect
[591835:591837:20221230,121506.968360:ERROR http_transport_socket.cc:570] SSLStream Initialize
[591835:591837:20221230,121506.968629:ERROR directory_reader_posix.cc:42] opendir /tmp/.../emu-crash.db/attachments/xyz: No such file or directory (2)
[591835:591837:20221230,121506.985868:ERROR http_transport_socket.cc:169] SSL_connect
[591835:591837:20221230,121506.985888:ERROR http_transport_socket.cc:570] SSLStream Initialize
[591835:591837:20221230,121506.986174:ERROR directory_reader_posix.cc:42] opendir /tmp/.../emu-crash.db/attachments/xyz: No such file or directory (2)
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
[591835:591837:20221230,121507.006321:ERROR http_transport_socket.cc:169] SSL_connect
[591835:591837:20221230,121507.006339:ERROR http_transport_socket.cc:570] SSLStream Initialize
[591835:591837:20221230,121507.006764:ERROR directory_reader_posix.cc:42] opendir /tmp/.../emu-crash.db/attachments/xyz: No such file or directory (2)
INFO    | Crash reports will be automatically uploaded to: https://clients2.google.com/cr/report
[591831:591831:20221230,121507.018195:ERROR file_io_posix.cc:152] open /tmp/.../emu-crash.db/pending/xyz.lock: File exists (17)
INFO    | Consent given for uploading crashreport ... to https://clients2.google.com/cr/report
INFO    | Consent given for uploading crashreport ... to https://clients2.google.com/cr/report
INFO    | Consent given for uploading crashreport ... to https://clients2.google.com/cr/report
WARNING | cannot add library ~/aosp/prebuilts/android-emulator/linux-x86_64/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
[591835:591837:20221230,121507.022230:ERROR http_transport_socket.cc:169] SSL_connect
[591835:591837:20221230,121507.022241:ERROR http_transport_socket.cc:570] SSLStream Initialize
INFO    | added library ~/aosp/prebuilts/android-emulator/linux-x86_64/lib64/vulkan/libvulkan.so
WARNING: lavapipe is not a conformant vulkan implementation, testing use only.
INFO    | Sending adb public key [...]
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO    | Advertising in: /run/user/1000/avd/running/pid_591831.ini
INFO    | Setting display: 0 configuration to: 1440x2960, dpi: 560x560 

The second time I ran emulator, I saw the UI for the Emulator with the Android splash screen. It was able to boot into the main home screen with app icons. However, shortly after (less than 1-2 minutes), I keep getting a segmentation fault:

$ emulator
INFO    | Android emulator version 31.3.9.0 (build_id 9070145) (CL:N/A)
INFO    | Storing crashdata in: /tmp/.../emu-crash.db, detection is enabled
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
INFO    | Crash reports will be automatically uploaded to: https://clients2.google.com/cr/report
WARNING | cannot add library ~/aosp/prebuilts/android-emulator/linux-x86_64/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
INFO    | added library ~/aosp/prebuilts/android-emulator/linux-x86_64/lib64/vulkan/libvulkan.so
WARNING: lavapipe is not a conformant vulkan implementation, testing use only.
INFO    | Sending adb public key [...]
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO    | Advertising in: /run/user/1000/avd/running/pid_3307.ini
INFO    | Setting display: 0 configuration to: 1440x2960, dpi: 560x560 
ERROR   | Unable to connect to adb daemon on port: 5037
INFO    | Boot completed in 25002 ms
INFO    | Increasing screen off timeout, logcat buffer size to 2M.
ERROR   | Unable to connect to adb daemon on port: 5037
INFO    | Revoking microphone permissions for Google App.
Segmentation fault (core dumped)

The third time running emulator, I encountered these logs and ended up following the suggestion to run emulator -read-only. The emulator's UI would appear briefly with "Phone starting..." on the splash screen but would crash shortly after:

$ emulator
INFO    | Android emulator version 31.3.9.0 (build_id 9070145) (CL:N/A)
INFO    | Storing crashdata in: /tmp/.../emu-crash.db, detection is enabled
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
ERROR   | Running multiple emulators with the same AVD 
ERROR   | is an experimental feature.
ERROR   | Please use -read-only flag to enable this feature.

$ emulator -read-only
INFO    | Android emulator version 31.3.9.0 (build_id 9070145) (CL:N/A)
INFO    | Storing crashdata in: /tmp/.../emu-crash.db, detection is enabled
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"
INFO    | Crash reports will be automatically uploaded to: https://clients2.google.com/cr/report
WARNING | cannot add library ~/aosp/prebuilts/android-emulator/linux-x86_64/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
INFO    | added library ~/aosp/prebuilts/android-emulator/linux-x86_64/lib64/vulkan/libvulkan.so
WARNING: lavapipe is not a conformant vulkan implementation, testing use only.
INFO    | Sending adb public key [...]
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO    | Advertising in: /run/user/1000/avd/running/pid_6440.ini
INFO    | Setting display: 0 configuration to: 1440x2960, dpi: 560x560 
ERROR   | Unable to connect to adb daemon on port: 5037
INFO    | Boot completed in 26070 ms
INFO    | Increasing screen off timeout, logcat buffer size to 2M.
ERROR   | Unable to connect to adb daemon on port: 5037
INFO    | Revoking microphone permissions for Google App.
ERROR   | detected a hanging thread 'QEMU2 main loop'. No response for 15000 ms
ERROR   | detected a hanging thread 'QEMU2 CPU0 thread'. No response for 15000 ms
ERROR   | detected a hanging thread 'QEMU2 CPU1 thread'. No response for 15000 ms
ERROR   | detected a hanging thread 'QEMU2 main loop'. No response for 15000 ms
Segmentation fault (core dumped)

The behavior of the emulator starting sometimes changes. I will sometimes see an immediate crash, delayed crash, indefinite black screen in the emulator and sometimes it will freeze my entire machine.

Is there a step that I am missing? Would I need to do anything special in terms of configuring my environment on Fedora 35? Would I need to install any other graphic libraries? I am basically interested in building the AOSP Emulator from scratch in order to test changes made to the Android Framework.

Additional question: what is the difference between the emulator for the following? Would the emulator be the same or different? How does lunch between (A) and (B) affect the emulator?

(Option A)

$ source build/envsetup.sh 
$ lunch sdk_phone_x86
$ m
$ emulator

(Option B)

$ source build/envsetup.sh 
$ lunch aosp_raven-userdebug
$ m
$ emulator

Solution

  • This issue has now been solved. It appears this may be a specific issue to Fedora + NVIDIA graphics but these are the steps I followed to resolve it. Hopefully this helps someone with a similar environment!

    1. Visit the NVIDIA website and download the latest drivers for your video card. The drivers along with an installation script should be available to run.
    2. Run the script. You might encounter a message to disable nouveau. If so, configuration files will be automatically created to disable nouveau. You might see the following scripts created automatically:
    $ cat /usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf
    # generated by nvidia-installer
    blacklist nouveau
    options nouveau modeset=0
    
    $ cat /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
    # generated by nvidia-installer
    blacklist nouveau
    options nouveau modeset=0
    
    1. Run the following to disable nouveau:
    $ dracut --regenerate-all -f 
    
    1. Reboot
    2. Run the NVIDIA drivers script again as root. This should succeed.
    3. Reboot
    4. Confirm nouveau is no longer enabled:
    lsmod | grep nouveau 
    

    After this, you should be able to run the emulator successfully.