1
votes

I have created some espresso UI tests. The tests are working fine locally(emulator and real device). But when I am trying to run the UI test on CircleCI. I am getting this error log

Task :app:compileFossDebugAndroidTestKotlin Compilation with Kotlin compile daemon was not successful java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:

Unable to clear jar cache after compilation, maybe daemon is already down: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: java.net.ConnectException: Connection refused (Connection refused) Could not connect to kotlin daemon. Using fallback strategy.

Picked up JAVA_TOOL_OPTIONS: -Xms512m

Task :app:compileFossDebugAndroidTestKotlin FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileFossDebugAndroidTestKotlin'.

More detail regarding error log is available here

Here is my config.yml file for circleci with run-ui-tests job

run-ui-tests:
    docker:
      - image: circleci/android@sha256:5cdc8626cc6f13efe5ed982cdcdb432b0472f8740fed8743a6461e025ad6cdfc
    environment:
      JVM_OPTS: -Xmx2048m
      GRADLE_OPTS: -Xmx1536m -XX:+HeapDumpOnOutOfMemoryError -Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false
    steps:
      - checkout
      - run:
          name: ANDROID_HOME
          command: echo "sdk.dir="$ANDROID_HOME > local.properties
      - run:
          name: restore files from ENV
          command: |
            echo $ROCKET_JKS_BASE64 | base64 --decode > Rocket.jks
            echo $ROCKET_PLAY_JSON | base64 --decode > app/rocket-chat.json
      - run:
          name: checkout Rocket.Chat.Kotlin.SDK
          command: git clone https://github.com/RocketChat/Rocket.Chat.Kotlin.SDK.git ../Rocket.Chat.Kotlin.SDK
      - restore_cache:
          key: kotlin-sdk-{{ .Revision }}
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Accept licenses
          command: yes | sdkmanager --licenses || true
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Setup emulator
          command: sdkmanager "system-images;android-22;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-22;default;armeabi-v7a"
      - run:
          name: Launch emulator
          command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel auto -verbose
          background: true
      - run:
          name: Wait emulator
          command: |
            # wait for it to have booted
            circle-android wait-for-boot
            # unlock the emulator screen
            sleep 30
            adb shell input keyevent 82
      - run:
          name: Run EspressoTests
          command: ./gradlew connectedAndroidTest
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results

gradle.properties

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

Other Configuration

compileSdk version           : 28
targetSdk version            : 28
kotlin version               : '1.3.31'

The project is having 2 flavors: foss and play and 2 build types: debug and release

I have tried all possible solution but none is working. Any help will be appreciated. Thanks

3

3 Answers

3
votes

Adding this line to config.yml helped me in avoiding this error

GRADLE_OPTS: -Xmx1536m -XX:+HeapDumpOnOutOfMemoryError -Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false

more info here : https://github.com/circleci/circleci-docs/issues/2945#issuecomment-471637158

1
votes

For a lot of people, it seems adding the GRADLE_OPTS line that you already have has helped resolve their unmarshaling error. For me, that line actually broke all of my unit tests before getting to the command that causes the unmarshaling error. For our build, our gradle memory was used up after running all of our unit tests. The solution was to clear the gradle cache after all of the unit tests ran, but before building and pushing to the store. We added the command rm -fr ~/.gradle/daemon/ to our travis file as user zhukunqian pointed out in the comments section.

0
votes

I meet the same problem.

And finally, I delete my gradle cache folder (linux: ~/.gradle), and this problem disappear.

You can try and kill gradle deamon first.

update: I found the reason is disable gradle deamon can sovle this problem. add org.gradle.daemon=false to gradle.properties

update2: sorry, everyone ,the reason this momery too low on my ECS (1 cpu, 1G memory), I add 1G swap and this problem disppear.