6

Seemingly the same root cause as this question, but the answer there will not work for me. I have a custom source set called commonTest that I use for sharing certain test utility code across the test and androidTest source sets. Here is my relevant project config:

sourceSets {
    // This lets us write test utility code that can be used by both unit tests and android tests
    commonTest {
        java
    }
    test {
        java.srcDirs += commonTest.java.srcDirs
    }
    androidTest {
        java.srcDirs += commonTest.java.srcDirs
    }
}

This worked fine with AGP 3.0.1, but breaks on AGP 3.1.0. Are custom source sets no longer supported?

AutonomousApps
  • 3,503
  • 2
  • 27
  • 39
  • 1
    Why do you need a source set for this? Can't this just be a common Java directory that you add via `java.srcDirs`? Is there something that you get from having it be a source set? – CommonsWare Apr 01 '18 at 18:25
  • Can you show me an example of that? I've used the source set approach successfully for _years_. – AutonomousApps Apr 01 '18 at 18:26
  • I think the main thing I get is that it "just works" (in the past) and my IDE recognizes it (in the past) as a java source set and renders it prettily. – AutonomousApps Apr 01 '18 at 18:31
  • See how you [add Room schemas to `assets`](https://developer.android.com/training/data-storage/room/migrating-db-versions.html). That's not in a separate source set. I can't find an example on my development machine of doing this with Java code; usually I just have that stuff be in a separate module. – CommonsWare Apr 01 '18 at 18:33
  • Ok, but it still doesn't answer my original question, which is "are custom source sets no longer supported?" For the room stuff, looks like you're referring to this: ``` sourceSets { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) } ``` – AutonomousApps Apr 01 '18 at 18:40
  • 2
    Yes, that's what I'm referring to. `$projectDir/schemas` is not in a source set, yet we add it anyway. [This seems to cover your concern](https://stackoverflow.com/questions/48846879/new-error-after-update-to-gradle-tool-to-3-1-0-beta3-or-3-2-0-alpha03/49512354#49512354), and [this seems to be an outstanding issue on the subject](https://issuetracker.google.com/issues/73536375). – CommonsWare Apr 01 '18 at 19:16
  • @AutonomousApps Hi have you managed to create custom sourceSet because am also strugling with this one? – xyman May 30 '19 at 09:30
  • 2
    Nope, gave up on that, although I'm sure it's somehow possible. What I do nowadays is just a separate test-only module and add it as a project dependency like `testImplementation(project(":android-test-utils"))` – AutonomousApps May 30 '19 at 18:32

0 Answers0