Search code examples
react-nativedetox

Detox + android Compiling DetoxTest.java fails


I'm trying to run

detox build -c android.emu.release

but it fails when it tries to compile DetoxTest.java with the following errors

  ~/android/app/src/androidTest/java/<package_name>/DetoxTest.java:24: error: cannot find symbol
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
                            ^
      symbol:   class MainActivity
      location: class DetoxTest

  ~/android/app/src/androidTest/java/<package_name>/DetoxTest.java:24: error: cannot find symbol
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
                                                                                 ^
  symbol:   class MainActivity
  location: class DetoxTest

I tried importing MainActivity from the package but I get the package cannot be found.

RN 0.51.1 Detox: 7.4.3


Solution

  • To solve this issue, follow closely the README for wix/detox/AndroidSupportStatus

    For example if your project name is myandroidproject (see property rootProject.name of settings.gradle below), DetoxTest.java will be at the following location inside the package com.myandroidproject.

    android/app/src/androidTest/java/com/myandroidproject/DetoxTest.java

    package com.myandroidproject
    

    ...

    settings.gradle

    rootProject.name = 'myandroidproject'
    

    ...

    In your case above, you have to replace package_name appropriately.