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?
Hate to be a necromancer here, but I encountered this problem and found a solution for this, so I thought I'd share.
Android does not allow you to define custom sourcesets anymore like you still can in regular gradle projects. This is probably because it would interfere with flavors, buildtypes and all the generated interdependent stuff that goes along with those. The default sourcesets are:
main
,debug
andrelease
and if you really want another one, you could add a buildtype or a flavor for which android then creates an accompanying sourceset. Here someone gives an example of that.In your case however it might be better to simply pull out the code into a separate (java) library and add a dependency on it in your android project. This is also what I ended up doing after trying to put multiple things into one project like I would with regular java/gradle projects. You can see here how to set up a separate library using a subproject in case you didn't know about those.