Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emulator does not show any graphics #37

Closed
aerymilts opened this issue Jun 9, 2020 · 9 comments
Closed

Emulator does not show any graphics #37

aerymilts opened this issue Jun 9, 2020 · 9 comments

Comments

@aerymilts
Copy link

aerymilts commented Jun 9, 2020

Description

Emulator shows black screen

image

Steps to reproduce the issue

$ docker run -it --rm -v $(pwd)/sdk:/sdk thyrlian/android-sdk bash -c 'cp -a $ANDROID_SDK_ROOT/. /sdk'
$ docker run -d -p 59.1: 5901 -p 2222:22 -v $(pwd)/sdk:/opt/android-sdk -v ~/.ssh/emulator.pub:/root/.ssh/authorized_keys -v $(pwd)/sdk_builder.sh:/root/sdk_builder.sh -v $(pwd)/com.amazon.kindle.apk:/root/com.amazon.kindle.apk thyrlian/android-sdk-vnc
$ ssh root@0.0.0.0 -p 2222

root@20448ea13e96:$ bash sdk_builder.sh

I've also tried toggling various gpu options and different system images to no avail.

# sdk_builder.sh

sdkmanager --update
sdkmanager "platform-tools" "platforms;android-24" "platforms;android-25" "emulator"
sdkmanager "system-images;android-24;default;armeabi-v7a"
sdkmanager "system-images;android-25;google_apis;armeabi-v7a"

export QTWEBENGINE_DISABLE_SANDBOX=1

echo 'no' | avdmanager create avd -n 24_test -k "system-images;android-24;default;armeabi-v7a"
echo 'no' | avdmanager create avd -n 25_test -k "system-images;android-25;google_apis;armeabi-v7a"
# INFO: List existing Android Virtual Devices
avdmanager list avd
# launch emulator
 emulator -avd 24_test -no-audio -no-boot-anim -gpu off
# emulator -avd 24_test -no-audio -no-boot-anim -accel on -gpu swiftshader_indirect &

The output looks like that
image

But rerunning the script a second time round gives just this, without the 'emulator out of date' output
image

Describe the results you expected

The ability to use the emulator through VNC visually.

@thyrlian
Copy link
Owner

Hi @aerymilts, I'm currently in the hospital and will check this once I'm back home.

In general, I've tested the container on my side before publishing it, I can view the emulator, interact with the emulator via mouse, and also run UI test on the emulator.

BTW, the warning you've got is not a big deal, you can totally ignore that.

Another matter is, virtualizing an ARM-based emulator, inside a docker container is a quite expensive action, for sure it will be slow. It may take even a few minutes before the real Android screen gets rendered properly.

I'll try to reproduce using the steps you've provided, and share the updates here.

@aerymilts
Copy link
Author

Hey @thyrlian, I'm sorry to hear that you're in hospital. I hope you get well soon.

I've tried leaving the emulator to start and render for up to half an hour at a time but nothing shows up.

Not sure if this bit of information helps, but I have also tried installing packages from the container and that didn't work. I'm wondering if this is a sign that the emulator hasn't booted properly.

root@20448ea13e96:$ adb install com.amazon.kindle.apk
Performing Streamed Install
adb: failed to install com.amazon.kindle.apk: Can't find service: package

As a thought, would running dind (Docker in Docker) allow for virtualizing an x86-based emulator instead? I intend to use the emulator to use apps that have better support on mobile vs desktop.

I didn't say this the first time round, but fantastic job on this repository and the support you're providing. I saw the level of details you were providing (and spelling out, in some cases) in the other resolved issues. 👍

@thyrlian
Copy link
Owner

Thank you @aerymilts for your acknowledgement and good wishes. I'm getting better now so I've played a bit.

By following the same steps you've listed, I'm able to launch the emulator and interact with it as well.

And I've tried both of the rendering options below, none of them has a problem.

emulator -avd 24_test -no-audio -no-boot-anim -gpu off &
emulator -avd 24_test -no-audio -no-boot-anim -accel on -gpu swiftshader_indirect &

As I said before, the virtualization inside Docker container is quite expensive, the bootup (readiness) of the emulator may take some minutes, which varies between machines (for instance: MacMini is way faster than MacbookPro). In fact, on my MacbookPro I haven't been waiting too long. And the other error message you've given - Can't find service: package tells that the bootup process is not finished yet (or properly). My suggestion would be: try with a powerful machine or some cloud service. Please forget about Docker in Docker, it won't help.

VNC 1

VNC 2

@aerymilts
Copy link
Author

Hey @thyrlian, appreciate you testing out my scripts on your setup. Good to know I've set it up correctly and it's just down to the hardware. It appears that my GPU is not shared with the container. I managed to get the emulator going by disabling automatic graphics switching. The interface is incredibly slow, as you've pointed out before.

Re: dind, I just went over the Emulator section again. Does this mean that there's absolutely no way for a Mac user to run x86 emulators (short of dual booting into Linux)? I did find that there are paid options out there that enabled nested virtualization but it seems like there's not much support for this.

I don't have any knowledge in this area - do you have any recommendations/thoughts?

@thyrlian
Copy link
Owner

Hi @aerymilts, it's really good to hear that now it works for you after your magic tweak on your host machine. I'd like to copy the screenshot here from the link you've given, for other users' reference, because Apple moves its "permalink" often. Actually this is something new to me since my MacbookPro only has an integrated graphic card, I don't even have such option (meaning the performance on my machine should be worse than yours, still I'm able to run UI test under acceptable timing).

yosemite-system-prefs-energy-saver-automatic-graphics-switching-disable

Regarding dind:

  • In general, it's not possible on macOS. However, it's not absolutely impossible, if you can manage to port KVM to macOS, plus a ton of hacks, it may work, probably that doesn't worth the effort.
  • Yes, not long ago VirtualBox started to support nested virtualization, gradually from AMD CPU to Intel CPU.
  • Ultimately, I would pay more attention to the intention rather than the solution. We could get it working in some way, but in the end, the performance won't make us satisfied. For the sake of debugging, or just playing around, the simplest solution would be the Intel x86 emulator which comes with Android Studio. The emulator inside a Docker container is designed for CI purpose, for UI test automation. And usually, the companies have powerful Linux machine on-premises, or pay some cloud computing services, there the support for x86 emulator inside Docker container is optimal. What do you think?

@aerymilts
Copy link
Author

@thyrlian, go for it. I hope this is helpful for someone else in the future as well. 😄 That's interesting. I think the reason why it doesn't work on my integrated graphics is because I have a bad habit of leaving my laptop on for weeks at a time, so there's usually resource leaks which doesn't work very well for high performing apps. For reference, here are the stats of my MBP
image

  • In general, it's not possible on macOS. However, it's not absolutely impossible, if you can manage to port KVM to macOS, plus a ton of hacks, it may work, probably that doesn't worth the effort.
  • Yes, not long ago VirtualBox started to support nested virtualization, gradually from AMD CPU to Intel CPU.

Thanks for sharing, that's where I ended up as I went down the rabbit hole. I'm pretty much stuck as virtualization and architectures is way out of depth for me.

  • Ultimately, I would pay more attention to the intention rather than the solution. We could get it working in some way, but in the end, the performance won't make us satisfied. For the sake of debugging, or just playing around, the simplest solution would be the Intel x86 emulator which comes with Android Studio. The emulator inside a Docker container is designed for CI purpose, for UI test automation. And usually, the companies have powerful Linux machine on-premises, or pay some cloud computing services, there the support for x86 emulator inside Docker container is optimal. What do you think?

My intent is to build an emulator that allows me to use mobile apps that requires low to moderate resources (think: smooth paging for Kindle for Android on an emulator), using open source tools, high reproducibility (container as code) and is easy to port across OSes. That's how I got to Docker and your project.

I also came across BlueStacks which serves my purpose pretty well (in fact it seems like it's meant for high performance mobile gaming). It's just that it's not open source and it doesn't have high configurability. I initially thought that I'd just have to go deeper into Docker to find the right setup to get it to work just like how BlueStacks does it. But it seems like there are limitations with Docker that just doesn't allow it. Is my understanding accurate?

@aerymilts
Copy link
Author

aerymilts commented Jun 19, 2020

For the sake of debugging, or just playing around, the simplest solution would be the Intel x86 emulator which comes with Android Studio.

I just realised, did you mean to say that using the x86 emulator with Android Studio natively on my MBP would work?

edit: From the Emulation section:

You can't run software that uses another virtualization technology at the same time that you run the accelerated emulator. For example, VirtualBox, VMWare, and Docker currently use a different virtualization technology, so you can't run them at the same time as the accelerated emulator.

Just realised that this means I would be able to use an x86 emulator only if Docker isn't running.

@thyrlian
Copy link
Owner

For my integrated graphics card, I also tend to leave my laptop running/hibernating for weeks, but I haven't run into any problem launching emulator inside a container.

I got your purpose now, and I don't think emulator in container is a good solution for you. Please go and give a try of the x86 emulator from Android Studio, that should serve your needs.

@aerymilts
Copy link
Author

Sorry for the late response. Yes, it seems that accelerated containerised emulation for Mac is a convoluted solution at best. Thank you for helping me with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants