Detox: detox test fails to install apk

What happened?

  1. I’ve setup Github Action to run detox tests.
  • sdk manager
  • platform tools
  • emulator
  • butler
  • adb
  1. Running detox test fails to install an apk. The pm install command fails every time after 45 seconds. Local tests are working.
13:14:19.683 detox[4431] DEBUG: [SPAWN_CMD, #25, cpid=4643] /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk
13:15:04.686 detox[4431] DEBUG: [SPAWN_END, #25, cpid=4643] /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk terminated with SIGTERM
13:15:04.818 detox[4431] TRACE: [SPAWN_TRY_FAIL, #25] 
13:15:04.828 detox[4431] DEBUG: [SPAWN_CMD, #25, cpid=4677] (Retry #1) /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk
13:15:49.975 detox[4431] DEBUG: [SPAWN_END, #25, cpid=4677] /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk terminated with SIGTERM
13:15:50.213 detox[4431] TRACE: [SPAWN_TRY_FAIL, #25] 
13:15:50.225 detox[4431] DEBUG: [SPAWN_CMD, #25, cpid=4[774](https://github.com/houserion/universage/runs/7212318253?check_suite_focus=true#step:21:778)] (Retry #2) /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk
13:16:35.268 detox[4431] DEBUG: [SPAWN_END, #25, cpid=4774] /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk terminated with SIGTERM
13:16:35.570 detox[4431] TRACE: [SPAWN_TRY_FAIL, #25] 
13:16:35.578 detox[4431] DEBUG: [SPAWN_CMD, #25, cpid=4904] (Retry #3) /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk
13:17:20.699 detox[4431] DEBUG: [SPAWN_END, #25, cpid=4904] /Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk terminated with SIGTERM
13:17:20.706 detox[4431] ERROR: ChildProcessError: `/Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk` failed with code null
    at ChildProcess.<anonymous> (/Users/runner/work/universage/universage/node_modules/child-process-promise/lib/index.js:132:23)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28)
    at Pipe.<anonymous> (node:net:687:12)

What was the expected behaviour?

I expect detox test to install Application.apk and launch tests.

Was it tested on latest Detox?

  • I have tested this issue on the latest Detox release and it still reproduces.

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: 19.7.1 React Native version: 0.64.3 Node version: 16.13.1 Device model: Pixel XL Android version: 12 Test-runner (select one): jest-circus

Detox logs

Detox logs
/bin/sh -c npx detox test --configuration houserion.android.e2e --loglevel trace --record-logs failing --record-videos failing
INFO    | boot completed
INFO    | boot time 25248 ms
INFO    | Increasing screen off timeout, logcat buffer size to 2M.
INFO    | Revoking microphone permissions for Google App.
13:13:01.583 detox[4428] INFO:  [test.js] DETOX_CONFIGURATION="houserion.android.e2e" DETOX_LOGLEVEL="trace" DETOX_RECORD_LOGS="failing" DETOX_RECORD_VIDEOS="failing" DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1657102381569 DETOX_USE_CUSTOM_LOGGER=true jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' e2e
13:13:05.524 detox[4431] TRACE: [DETOX_CREATE] created a Detox instance with config:
{
  appsConfig: {
    default: {
      type: 'android.apk',
      binaryPath: 'android/app/build/outputs/apk/houserion/e2e/app-houserion-e2e.apk',
      build: 'cd ./android && RN_SRC_EXT=e2e.js,e2e.ts,e2e.tsx APP=houserion BUILD_TYPE=e2e GENERATE_SOURCEMAP=false ./gradlew assembleHouserionE2e assembleHouserionE2eAndroidTest -DtestBuildType=e2e && cd ..'
    }
  },
  artifactsConfig: {
    rootDir: '.artifacts/houserion.android.e2e.2022-07-06 10-13-01Z',
    plugins: {
      log: {
        enabled: true,
        keepOnlyFailedTestsArtifacts: true
      },
      screenshot: {
        enabled: true,
  ● Deep Link, Guest › should work
    Environment setup failed. See the detailed error below.
  ● Deep Link, Guest › should work
    Environment setup failed. See the detailed error below.
  ● Deep Link, Authorized › should onboard
    Environment setup failed. See the detailed error below.
  ● Deep Link, Authorized › should work
    Environment setup failed. See the detailed error below.
  ● Deep Link, Broken › should work
    Environment setup failed. See the detailed error below.
  ● Test suite failed to run
    ChildProcessError: `/Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk` failed with code null
      at ChildProcess.<anonymous> (../node_modules/child-process-promise/lib/index.js:[132](https://github.com/houserion/universage/runs/7212318253?check_suite_focus=true#step:21:136):23)
13:17:49.456 detox[4431] TRACE: [SESSION_TORN] tester exited session 695db362-0f12-2db8-f69f-fe39da698771
13:17:49.961 detox[4428] ERROR: [cli.js] Command failed: jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' e2e

Device logs

Device logs
paste logs here!

More data, please!

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 26 (3 by maintainers)

Most upvoted comments

I have the exactly same issue, but using Bitrise CI.

I can find the device via adb -s emulator-5554 emu avd name

But when running the

detox test -c android.emu.release

I have the issue:

detox[8453] INFO:  [test.js] DETOX_CLEANUP=true DETOX_CONFIGURATION="android.emu.release" DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1657707517233 DETOX_USE_CUSTOM_LOGGER=true jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' e2e

detox[8465] ERROR: ChildProcessError: `/opt/android-sdk-linux/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk` failed with code null
    at ChildProcess.<anonymous> (/bitrise/src/app/node_modules/child-process-promise/lib/index.js:132:23)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

Everyone facing this issue - please follow the suggestion of bundling the installation of the apk (or any other APK) in your buildscripts, prior to Detox, and see whether that works.

@RohovDmytro since in your case the command terminates with a SIGTERM, I postulate that github-actions doesn’t approve of something happening in your environment, and therefore terminates the command prematurely. Since you mentioned 45 seconds, I would guess an enforcement of a timeout of some sort.

Exact same issue for Github Actions here. Is everyone trying to install on an x86_64 emulator?

@d4vidi thank you for suggestion, we do that everything except running adb install manually We’ll try it out and update you Screenshot 2022-08-30 at 15 36 49

Why is this closed? 😦

@d4vidi would Detox consider changing the INSTALL_TIMEOUT value that @david-alza found, given that it appears to be affecting others?


largely suggesting to launch the emulators in advance, build your apps (e.g. using detox build) and run adb install manually before running detox test (which, in turn, should be run with the --reuse argument)

If the timeout will not be changed and these installation steps should be indeed reused maybe it would be good to get a guide on which commands with which flags are implied here for CI users…

With a few tests it seems like bumping this timeout up to 90s did resolve our issues here, though it’s hard to say with certainty since these were always a bit flakey overall… not sure what’s the root cause of the slow install times.

Logging the timeouts doesn’t seem possible actually since the timeout argument is just being passed down into node’s child_process.exec command which will just SIGTERM a command on timeout without a specific message [source]

I tried with the flag forceAdbInstall but it didn’t result,

I also I tried installing manually both apk’s generated from build

  • android/app/build/outputs/apk/release/app-release.apk
  • android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk

The installation was successfull as you’ll see on logs, however it fails when trying to run the detox test -c android.emu.release

Performing Streamed Install
Success
Performing Streamed Install
Success
00:10:29.053 detox[8892] INFO:  [test.js] DETOX_CONFIGURATION="android.emu.release" DETOX_REPORT_SPECS=true DETOX_START_TIMESTAMP=1660176629017 DETOX_USE_CUSTOM_LOGGER=true jest --config e2e/config.json --testNamePattern '^((?!:ios:).)*$' e2e
00:13:43.968 detox[8904] ERROR: ChildProcessError: `/opt/android-sdk-linux/platform-tools/adb -s emulator-5554 shell pm install -r -g -t /data/local/tmp/detox/Application.apk` failed with code null
    at ChildProcess.<anonymous> (/bitrise/src/app/node_modules/child-process-promise/lib/index.js:132:23)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

@ErickMaeda @Arron-Gill Can you try to install the apk manually from the commandline and check whether that works for you? Also, if you run the tests locally, and not through bitrise, do they work as expected? Do you see any relevant messages in the adb logcat when the problem occurs?