Search code examples
react-nativedetox

Detox successfully builds but does not install app on Android emulator


I'm getting a successful detox build, and the emulator starts up, but the app is just never installed.

react-native run-android (without Detox) works fine.

The only error I'm seeing (including in verbose mode) is: "No instrumentation runner found", but I'm guessing that just means Detox can't find the app (which was never installed).

How can I get Detox to actually install the app onto the emulator? The only clue I see is that the package name has .test appended in this case which may be an issue, but I'm not at all sure of that.

(I tried to adb install the test app but that doesn't fix the issue, and also nothing shows up in the emulator when I run the command: adb -e install android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk. This installation command works fine for our standard debug apk.)

Log:

BUILD SUCCESSFUL in 25s
1029 actionable tasks: 1 executed, 1028 up-to-date
detox[66003] INFO:  [test.js] configuration="android.emu.debug" reportSpecs=true readOnlyEmu=false useCustomLogger=true forceAdbInstall=false DETOX_START_TIMESTAMP=1597412615185 node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e
detox[66004] INFO:  [DetoxServer.js] server listening on localhost:55217...
detox[66004] ERROR: Error: No instrumentation runner found on device emulator-11448 for package com.myco.myapp.test
detox[66004] INFO:  Example is assigned to undefined
detox[66004] INFO:  Example: should have welcome screen
detox[66004] INFO:  Example: should have welcome screen [SKIPPED]

detox[66003] ERROR: [cli.js] Error: Command failed: node_modules/.bin/jest --config e2e/config.json '--testNamePattern=^((?!:ios:).)*$' --maxWorkers 1 e2e

detoxrc entry:

    "android.emu.debug": {
      "binaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
      "testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
      "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_API_28_AOSP"
      }
    },

Solution

  • This had to do with APK paths. Detox tries to compute a debug APK path, and if it's wrong it will come up with these errors. (If you build multiple versions of your APKs for different architectures, Detox doesn't appear to be able to handle that.)

    The solution is to point to both of your APKs - the debug app ("binary"), and the instrumentation APK ("test binary"):

          "binaryPath": "android/app/build/outputs/apk/debug/app-x86_64-debug.apk",
          "testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",