amrsa1 / Android-Emulator-image

The use of this Docker image simplifies the process of running an Android emulator within a Docker container
MIT License
113 stars 52 forks source link

Is it suppose to work on MacOS with Apple Silicon arm chip? #10

Open Hatgor opened 1 year ago

Hatgor commented 1 year ago

I did my best to run your docker container on my M1 laptop, but unfortunately I failed.

Cases I tried:

  1. Direct docker run without specifing platform. Got Warning: Dependant package with key emulator not found! and process failure.
  2. Docker run with platform=linux/amd64 flag Container itself started, but after execution start_emu_headless.sh all I got is adb: device offline, wait for boot till timeout expired.

I shall try one more time with a separate VirtualBox in x86 mode, but before investing additional time in this, may I ask if I did miss something? Is there any simplier solution?

amrsa1 commented 1 year ago

@Hatgor It should be working fine with m1 chip, how much is the timeout, did you try to increase it ?

wman1980 commented 1 year ago

I am also facing this issue on my apple m1 machine.

I build my docker container via: docker build -t android-emulator .

Resulting in a build error: ERROR [5/6] RUN yes Y | sdkmanager --verbose --no_https system-images;android-33;google_apis_playstore;arm64-v8a platforms;android-33 build-tools;33.0.2 platform-tools

As @Hatgor wrote adding platform=linux/amd64 to the docker build command fixes this issue: docker build --platform linux/amd64 -t android-emulator .

Afterwards I can successfully do the following things:

  1. Initiate docker container as described here
  2. Instantiate the VNC service
  3. Connect to the VNC server via VNCViewer
  4. Open dash terminal in vnc viewer

Unfortunately there are now a few other issues:

  1. I can open a bash and run ./start_emu.sh.

This fails saying that it can not find emulator or adb commands. I fixed this by changing the path to emulator and adb within ./start_emu.sh to ./opt/android/emulator/emulator and ./opt/android/platform-tools/adb

  1. Now my emulator tries to start, but fails with error that hardware acceleration is not available. This is maybe due docker build --platform=linux/amd64, but I am not sure. I fixed this by telling the emulator to not use hardware acceleration via emulator -no-accel

Now my emulator window within my vnc viewer pops up, but it seems that it's not working correctly, at least the emulator does not boot up and I do not see any android home screen. Also closing my emulator results in a fatal exception. There is also a warning that emulator might not work correctly without hardware acceleration.

What I'll try now is to build the docker image with platform linux/arm64 and finding out why the system-image cannot be installed. That's basically also the same issue while building the docker image without the platform option at all.

Basically just the following command fails if docker container is build with or without platform=linux/arm64 option: sdkmanager --verbose --no_https "system-images;android-33;google_apis_playstore;arm64-v8a"

Saying:

Info: Parsing legacy package: /opt/android/cmdline-tools/tools
Warning: Dependant package with key emulator not found!                         
Warning: Unable to compute a complete list of dependencies. 

And I do not know why it can not install the system image ...

amrsa1 commented 1 year ago

Unfortunately it will be hard to launch the emulator in GUI mode via VNC, actually you can try the -no-accel -gpu swiftshader but performance will be very poor.

only option for now it launch in headless mode since virtualisation wont be needed.

@Hatgor @wman1980

carTloyal123 commented 10 months ago

Hi, I am facing a similar issue but my question is why the build fails if specifying "--platform linux/arm64" or specifying no platform at all? It is not clear to me why sdkmanager cares if the container it is in is arm64 or amd64 or any other architecture variant. Any idea on why this might be an issue? Love the repo by the way thank you!

carTloyal123 commented 10 months ago

It looks like there are issues with downloading arm versions of the android build tools. Not sure there is an easy fix but wanted to give an update that it looks like an android/google issue not Docker or this repo specifically.

amrsa1 commented 10 months ago

It looks like there are issues with downloading arm versions of the android build tools. Not sure there is an easy fix but wanted to give an update that it looks like an android/google issue not Docker or this repo specifically.

You will be able to build the image with this command : docker buildx build --platform linux/amd64 -t android-emulator .

nihartsx commented 8 months ago

i am able to build the image on M1 using that command but unable to run the emulator in headless mode.

Docker build command docker buildx build --platform linux/amd64 -t android-emulator .

start emulator in headless mode. I increased timeout. docker exec --privileged -it -e EMULATOR_TIMEOUT=700 androidContainer bash -c "./start_emu_headless.sh" Output daemon not running; starting now at tcp:5037 daemon started successfully linux-gnu: emulator @nexus -no-window -no-snapshot -noaudio -no-boot-anim -memory 2048 -accel off -camera-back none -gpu off nohup: appending output to 'nohup.out' ==> Checking emulator booting up status 🧐 ==> adb: device offline, please wait ⠏

Attempted debugging:

  1. More than doubled the timeout
  2. Tried to start the emulator using emulator @Pixel7 -no-window -no-audio -no-boot-anim and received this error about hardware acceleration being needed.

root@616e7e20049f:/# emulator @Pixel7 -no-window -no-audio -no-boot-anim INFO | Storing crashdata in: /tmp/android-unknown/emu-crash-34.1.19.db, detection is enabled for process: 2305 INFO | Android emulator version 34.1.19.0 (build_id 11525734) (CL:N/A) ERROR | Unknown AVD name [Pixel7], use -list-avds to see valid list. ERROR | HOME is defined but there is no file Pixel7.ini in $HOME/.android/avd ERROR | (Note: Directories are searched in the order $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/avd and $HOME/.android/avd) root@616e7e20049f:/# emulator @nexus -no-window -no-audio -no-boot-anim INFO | Storing crashdata in: /tmp/android-unknown/emu-crash-34.1.19.db, detection is enabled for process: 2316 INFO | Android emulator version 34.1.19.0 (build_id 11525734) (CL:N/A) INFO | Found systemPath /opt/android/system-images/android-31/google_apis_playstore/x86_64/ INFO | Storing crashdata in: /tmp/android-unknown/emu-crash-34.1.19.db, detection is enabled for process: 2316 INFO | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag. WARNING | Please update the emulator to one that supports the feature(s): Vulkan INFO | Increasing RAM size to 2048MB WARNING | File System is not ext4, disable QuickbootFileBacked feature ERROR | x86_64 emulation currently requires hardware acceleration! CPU acceleration status: /dev/kvm is not found: VT disabled in BIOS or KVM kernel module not loaded More info on configuring VM acceleration on Linux: https://developer.android.com/studio/run/emulator-acceleration#vm-linux General information on acceleration: https://developer.android.com/studio/run/emulator-acceleration. root@616e7e20049f:/#

carTloyal123 commented 8 months ago

I have an image up and running successfully. I will post the docker file here when I am back to my computer. It runs on Apple silicone and can run android apps headless.

carTloyal123 commented 8 months ago

You can see a working example in my repo here: Cryze-Android Docker Files

The useful parts are the dockerfile in the android folder and the run_emu.sh file which actually starts the emulator when a new container is created. Hope this helps!

nihartsx commented 8 months ago

thanks @carTloyal123. Appreciate it very much, i will take a look.

amrsa1 commented 8 months ago

You can see a working example in my repo here: Cryze-Android Docker Files

The useful parts are the dockerfile in the android folder and the run_emu.sh file which actually starts the emulator when a new container is created. Hope this helps!

Good job man, feel free to contribute and adjust the existing dockerfile if you dont mind.

jperez3 commented 6 months ago

You can see a working example in my repo here: Cryze-Android Docker Files The useful parts are the dockerfile in the android folder and the run_emu.sh file which actually starts the emulator when a new container is created. Hope this helps!

Good job man, feel free to contribute and adjust the existing dockerfile if you dont mind.

lol he's like "nah"

carTloyal123 commented 6 months ago

@jperez3 feel free to update this repo and submit a PR

Otherwise, I will get to it when I can. @amrsa1 I appreciate the work you have done in this repo and the first thing on my list for when I have time for side projects again is to add my changes back to your repo.

amrsa1 commented 6 months ago

@carTloyal123 Np, you are welcome whenever you can

jperez3 commented 6 months ago

@jperez3 feel free to update this repo and submit a PR

Otherwise, I will get to it when I can. @amrsa1 I appreciate the work you have done in this repo and the first thing on my list for when I have time for side projects again is to add my changes back to your repo.

I'm assessing both right now, the original is having issues finding adb when running emulator.sh (piping path to .bashrc doesn't fix it) and yours is missing instructions on the copy of the emulator folder (i see the ec2 notes and gitignore for that folder) + it's erroring on the avdmanager command during the build

codingBird19 commented 2 months ago

It looks like there are issues with downloading arm versions of the android build tools. Not sure there is an easy fix but wanted to give an update that it looks like an android/google issue not Docker or this repo specifically.

You will be able to build the image with this command : docker buildx build --platform linux/amd64 -t android-emulator .

Hi, I am able to build the image successfully and created container with these commands: docker buildx build --platform linux/amd64 -t android-emulator . --progress=plain

docker run -it -d -p 5900:5900 --platform=linux/amd64 --device /dev/kvm android-emulator

However, whenever I am performing command: "adb devices" it doesn't list any device. Could you please help me knowing why? I am having docker desktop installed on my Mac M1 machine.

amrsa1 commented 2 months ago

@codingBird19

I think best way to debug is buy running the docker container in interactive mode and start building and launching the emulator and check the logs