Enabling NDK In Project Causes Directories to be Seen as Packages

I have quite a complex project with many build variants and custom source sets. I have recently integrated the NDK and noticed something strange. Nothing is broken, everything seems to be working as it should. I’m thinking its a bug with Android Studio, unless something is wrong in the gradle config.

I added the following to my app/build.gradle

externalNativeBuild {
    cmake {
        path "CMakeLists.txt"

ndkVersion "22.0.6917172"

I then noticed that the directories within the "Project" pane of Android Studio were then displaying as if they were packages. It also looked as if every variant was being processed as well even though I am setting to be ignored.

This is what the directories looked like before

Before adding NDK

And this is what they look like now

After adding NDK

The bigger issue is that custom source sets for build variants were being included at the app/src/ level with just the kotlin directory?

custom source sets

These are configured in the app/build.gradle like this example.

android {
    sourceSets {
        padoq.java.srcDirs += "src/standardTileHandler/kotlin"
padoq.java.srcDirs += nonHsdSource

Before, in project view, these appeared as the directory name with the packages inside, not with the kotlin directory at the root. Here is what it looked like before:

custom source set before

For completeness, I am ignoring certain build variants by setting the variant to be ignored in the root build.gradle‘s subprojects block:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            def androidProperty = project["android"]
            if (androidProperty.hasProperty("flavorDimensionList")) {
                def flavorDimensions = androidProperty["flavorDimensionList"]
                if (flavorDimensions != null && flavorDimensions.contains("bopad")) {
                    androidProperty.invokeMethod("variantFilter", { variant ->
                        def names = variant.flavors*.name
                        // if names does not contain a variant that I want to build right now

Source: Windows Questions C++