Code Monkey home page Code Monkey logo

Comments (11)

ozmium avatar ozmium commented on July 30, 2024 2

Here are a few things to try:

  1. After you run ./android-wait-for-emulator, consider waiting for another 2-3 minutes before starting the tests in the next command. You can use a simple sleep 180 command. When an emulator is created and started from scratch, it has to do many things when booting for the first time. It's like a factory reset of the device. The long wait is needed to allow the emulator to do these things, like connect to Wifi, initialize the SD card storage space, optimize all the pre-installed apps, start the Home Screen app, and so on. I assume that you see the error com.android.ddmlib.ShellCommandUnresponsiveException because emulator is still doing all these things and is not yet ready to install and launch external apps.

  2. Try using an older Android OS version as your emulator, like Android 5 (API 21, 22) or Android 6 (API 23).

  3. Try using the -no-boot-anim and -gpu off flags when launching the emulator command. They are mentioned here: https://andresand.medium.com/android-emulator-on-docker-container-f20c49b129ef

Let us know if any of these suggestions worked for you.

from docker-android-build-box.

felHR85 avatar felHR85 commented on July 30, 2024 1

I've managed to get my tests working with the following changes
Android image changed to 23:
sdkmanager "system-images;android-23;default;armeabi-v7a"

Increasing ADB_INSTALL_TIMEOUT variable:
export ADB_INSTALL_TIMEOUT=30

from docker-android-build-box.

ozmium avatar ozmium commented on July 30, 2024 1

@felHR85 Yes I agree 100%. Actually it's the first time I've ever heard of the ADB_INSTALL_TIMEOUT technique. So thanks for the insight. It seems to work for many people:

Consider adding that info to this project's Readme file.

from docker-android-build-box.

felHR85 avatar felHR85 commented on July 30, 2024

@goemic
Did you finally manage to get this working?

from docker-android-build-box.

felHR85 avatar felHR85 commented on July 30, 2024

@ozmium
Those suggestions are what I finally added to my script to get it working. I would also suggest to add the ADB_INSTALL_TIMEOUT that I mentioned previously to avoid the 2 min timeout that is the default timeout for ADB.

from docker-android-build-box.

nikhil-seth avatar nikhil-seth commented on July 30, 2024

@felHR85 @ozmium Can you share the updated script.
I tried this, but my docker/ bitbucket pipeline hangs on launching emulator

from docker-android-build-box.

felHR85 avatar felHR85 commented on July 30, 2024

@nikhil-seth Where is your pipeline hanging?

This is the script that I am currently using with Bitbucket pipelines

#!/bin/bash

# ADB installation timeout needs to be increased
export ADB_INSTALL_TIMEOUT=30

# Create repositories if repositories.cfg file doest not exists.
touch /opt/android-sdk/.android/repositories.cfg

# Install Jenv(https://www.jenv.be/)
git clone https://github.com/jenv/jenv.git ~/.jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

# Add Java 11
jenv add /usr/lib/jvm/java-11-openjdk-amd64
jenv local system

# Add sys image sources
echo "src01=https\://dl.google.com/android/repository/sys-img/android/sys-img.xml" | tee -a /opt/android-sdk/.android/repositories.cfg
echo "src00=https\://dl.google.com/android/repository/sys-img/google_apis/sys-img.xml" | tee -a /opt/android-sdk/.android/repositories.cfg

# Download an ARM system image to create an ARM emulator.
sdkmanager "system-images;android-23;default;armeabi-v7a"

# Create an ARM AVD emulator, with a 100 MB SD card storage space. Echo "no"
# because it will ask if you want to use a custom hardware profile, and you don't.
echo "no" | avdmanager create avd \
    -n Android_API_24 \
    -k "system-images;android-23;default;armeabi-v7a" \
    -c 100M \
    --force

# Start emulator
$ANDROID_HOME/emulator/emulator -avd Android_API_24 -no-audio -no-window &
EMULATOR_PID=$!

# Wait until emulator is running
set +e

bootanim=""
failcounter=0
timeout_in_sec=360

until [[ "$bootanim" =~ "stopped" ]]; do
  bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
  if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline" || "$bootanim" =~ "running" ]]; then
    let "failcounter += 1"
    echo "Waiting for emulator to start ${failcounter}"
    if [[ $failcounter -gt timeout_in_sec ]]; then
      echo "Timeout reached; failed to start emulator"
      kill ${EMULATOR_PID}
      exit 1
    fi
  fi
  sleep 1
done

echo "Emulator is ready"

# Unlock the Lock Screen
adb shell input keyevent 82

sleep 180

# DO YOUR STUFF (TESTS I GUESS)
TEST_STATUS=$?

kill ${EMULATOR_PID}
exit ${TEST_STATUS}

from docker-android-build-box.

nikhil-seth avatar nikhil-seth commented on July 30, 2024
Task ':library:connectedDebugAndroidTest' is not up-to-date because:
  Task.upToDateWhen is false.
[DeviceMonitor]: Connected to adb for device monitoring
DeviceConnector 'Android_API_24(AVD) - 6.0': installing /opt/atlassian/pipelines/agent/build/library/build/outputs/apk/androidTest/debug/library-debug-androidTest.apk
AAPT2 aapt2-4.0.2-6197926-linux Daemon #21: shutdown
AAPT2 aapt2-4.0.2-6197926-linux Daemon #20: shutdown
AAPT2 aapt2-4.0.2-6197926-linux Daemon #10: shutdown
AAPT2 aapt2-4.0.2-6197926-linux Daemon #13: shutdown
----- End of the daemon log -----

FAILURE: Build failed with an exception.
* What went wrong:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

It is unable install the apk. Daemon shuts down abruptly after some time.

from docker-android-build-box.

felHR85 avatar felHR85 commented on July 30, 2024

@nikhil-seth
There are a couple of possible solutions in this SO thread. I hope this sheds some light. https://stackoverflow.com/questions/41684610/errorfailed-to-complete-gradle-execution-cause-gradle-build-daemon-disappear/44693275#44693275

from docker-android-build-box.

ozmium avatar ozmium commented on July 30, 2024

@nikhil-seth -- It could be a low-memory issue on your build machine, or a problem when using an emoji character somewhere. See:

If possible, try to monitor the memory usage of your Docker container, regularly, and check which processes are using a lot of memory. Or perhaps try to increase the memory allocation of the Docker instance.


Another option is to try to use an older Android OS version, like Android 5.0 or 5.1, which will probably use less memory.

  • "system-images;android-21;default;armeabi-v7a" -- Android 5.0, API 21
  • "system-images;android-22;default;armeabi-v7a" -- Android 5.1, API 22

from docker-android-build-box.

nikhil-seth avatar nikhil-seth commented on July 30, 2024

Thanks @ozmium @felHR85 . It started working. Issue was with memory only. Added 2x in size & it worked perfectly.

from docker-android-build-box.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.