5

I've a shared test folder configured like this in my gradle file:

        androidTest {
            java.srcDirs += "src/sharedTest/java"
        }
        test {
            java.srcDirs += "src/sharedTest/java"
        }

However, at startup I'm getting this error from Android Studio:

Duplicate content roots detected
            Path [/Users/fil/Documents/projects/deploy/app/build/generated/source/r/debug] of module [deploy.app.unitTest] was removed from modules 

Any idea on how to fix the issue? I've found that I might use test fixtures but I've not found a practical guide to follow :(

Filnik
  • 352
  • 1
  • 12
  • 33

2 Answers2

1

This is an issue and you can follow its status here: https://issuetracker.google.com/issues/220326930

As to fix this, you might:

  • Revert the Android Gradle plugin back to version: 7.1.3

Or refer to the latest comment on this topic: https://issuetracker.google.com/issues/232007221

A fix for this issue is now available in:

Android Studio Dolphin Beta 2 (2021.3.1.11)

Android Gradle Plugin 7.3.0-beta02

0

Update: I was able to make it work using the suggestion and the example project I found here: Shared srcDirs between test and androidTest, unresolved references after upgrade to Android Studio Chipmunk (IntelliJ 2021.2.1)

The most difficult parts where:

  • match correctly productFlavors. Otherwise everything won't work correctly

  • I'm still importing shared tests from shared folder in order to launch them with the unit test suite (they are robolectric tests so I want also to launch them visually in case of need). Like this:

    test {
        java.srcDirs += "../shared/src/test/java"
    }
    
  • put the correct testInstrumentationRunner also in the shared gradle since it was a custom one

  • import all the shared code in the main package even if it's used in tests (beside actual tests that are in the test folder)

I've updated gradle plugin to 7.2.2 only and I didn't update Android Studio to beta versions to make it work.

Filnik
  • 352
  • 1
  • 12
  • 33