amrsa1 / Android-Emulator-image

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

headless Emulator exiting after starting with no error message #12

Closed nkshschdv closed 10 months ago

nkshschdv commented 10 months ago

Command to build docker image Steps:

  1. Build an image $ docker build --build-arg ARCH=x86_64 --build-arg TARGET=google_apis_playstore --build-arg API_LEVEL=31 --build-arg BUILD_TOOLS=31.0.0 --build-arg EMULATOR_DEVICE="Nexus 6" --build-arg EMULATOR_NAME=nexus -t my-android-image .

  2. Running the container $ docker run -it --privileged -d -p 5900:5900 -p 5901:5901 --name androidContainer --privileged my-android-image

  3. I have to perform this command as windows OS was adding it's own characters after cloning to bash files seems $ docker exec --privileged -it -e EMULATOR_TIMEOUT=300 androidContainer bash -c "sed -i -e 's/\r$//' start_emu_headless.sh"

  4. Start the emulator $ docker exec --privileged -it androidContainer /bin/dash -c "./start_emu_headless.sh"

image

  1. however after i check the emulator status with below command , it shows that it has no devices attached $ docker exec --privileged -it androidContainer /bin/dash -c "adb devices "

image

Why the devices start but exit just after executing ? What is the way to persist it ?

nkshschdv commented 10 months ago

So funny to answer my own question , but i found the solution jsut now , and it is working as expected. here https://stackoverflow.com/questions/42218957/dockerfile-cmd-instruction-will-exit-the-container-just-after-running-it

Changed the emulator start command with the following $ docker exec --privileged -it androidContainer /bin/dash -c "./start_emu_headless.sh ; sleep infinity"

amrsa1 commented 10 months ago

Command to build docker image Steps:

  1. Build an image $ docker build --build-arg ARCH=x86_64 --build-arg TARGET=google_apis_playstore --build-arg API_LEVEL=31 --build-arg BUILD_TOOLS=31.0.0 --build-arg EMULATOR_DEVICE="Nexus 6" --build-arg EMULATOR_NAME=nexus -t my-android-image .
  2. I have to perform this command as windows OS was adding it's own characters after cloning to bash files seems $ docker exec --privileged -it -e EMULATOR_TIMEOUT=300 androidContainer bash -c "sed -i -e 's/\r$//' start_emu_headless.sh"
  3. Start the emulator $ docker exec --privileged -it androidContainer /bin/dash -c "./start_emu_headless.sh"

image

  1. however after i check the emulator status with below command , it shows that it has no devices attached $ docker exec --privileged -it androidContainer /bin/dash -c "adb devices "

image

Why the devices start but exit just after executing ? What is the way to persist it ?

Does it exit and terminate the container or just exiting ?

nkshschdv commented 10 months ago

Command to build docker image Steps:

  1. Build an image $ docker build --build-arg ARCH=x86_64 --build-arg TARGET=google_apis_playstore --build-arg API_LEVEL=31 --build-arg BUILD_TOOLS=31.0.0 --build-arg EMULATOR_DEVICE="Nexus 6" --build-arg EMULATOR_NAME=nexus -t my-android-image .
  2. I have to perform this command as windows OS was adding it's own characters after cloning to bash files seems $ docker exec --privileged -it -e EMULATOR_TIMEOUT=300 androidContainer bash -c "sed -i -e 's/\r$//' start_emu_headless.sh"
  3. Start the emulator $ docker exec --privileged -it androidContainer /bin/dash -c "./start_emu_headless.sh"

image

  1. however after i check the emulator status with below command , it shows that it has no devices attached $ docker exec --privileged -it androidContainer /bin/dash -c "adb devices "

image Why the devices start but exit just after executing ? What is the way to persist it ?

Does it exit and terminate the container or just exiting ?

No, it's not exiting the container it still show running in docker ps command . I missed to mention in my question , how i run the container. I added that as well.

nkshschdv commented 10 months ago

I'm assuming this is not happeniing to you @amrsa1. You are using which OS ?

amrsa1 commented 10 months ago

I'm assuming this is not happeniing to you @amrsa1. You are using which OS ?

Thats the expexted behavior, because terminal is exist the container becase the bash funcntions are executed successfully. So terminal will exit but container is still working in background you can still access the emulator and container

amrsa1 commented 10 months ago

Not an issue