Testing source directories for Multi Dimension Flavors not recognized in Android Studio
I have a problem with androidTest test and source directories for multidimensional accessories.
Considering the following tastes:
flavorDimensions "taste", "serving"
productFlavors {
chocolate {
flavorDimension "taste"
}
strawberry {
flavorDimension "taste"
}
kiwi {
flavorDimension "taste"
}
sample {
flavorDimension "serving"
}
whole {
flavorDimension "serving"
}
}
Android Studio has no problem with "non-test" source directories (any combination of flavors):
src / sample, src / whole, src / chocolate, src / strawberry, src / kiwi, src / chocolateSample, src /Whole, src / chocolateSample, src / strawberryWhole, src / kiwiSample, src / kiwiWhole
My problem is with "test" source directories.
Only one size fragrances are recognized: src / testSample, src / testWhole, src / testChocolate, src / testStrawberry, src / testKiwi.
Multimedia flavors are not: src / testChocolateSample, src / testChocolateWhole, src / testStrawberrySample, src / testStrawberryWhole, src / testKiwiSample, src / testKiwiWhole
This also applies to equivalent "androidTest" source directories.
I am under the impression that it is the app.iml that is being generated incorrectly. Realizing that we will NEVER do this, the folders will be recognized correctly if I have to manually add the missing entries.
Why would this work with non-test source directories, but errors with original source directories? Is this a known issue or limitation of the gradle plugin?
I tried to look into this, but only found topics related to individual flavor sizes for source folders or multidimensional variations for non-test source folders. There is nothing about multidimensional flavors for source folders.
source to share
You can fix this by modifying your Android app file build.gradle
. For example, to add testChocolateSample
to unit tests and testChocolate
to Android integration tests:
android {
[...]
sourceSets {
main.java.srcDirs += 'src/main/java'
testChocolateSample.java.srcDirs += 'src/testChocolateSample/java'
androidTestChocolate.java.srcDirs += 'src/androidTestChocolate/java'
}
}
This also works for Kotlin. Just switch java
to kotlin
.
source to share