"Cannot find symbol variable BuildConfig" with multiple source folders

Viewed 12702

I'm working with a project that have a lot of legacy code. I need to keep separated the "old code" from the new one. So I created the following directories:

-ProjectRoot
  -app
    -src
      -main
        -java
        -java_legacy
        -res
        -res_legacy

And added the following block to my build.gradle:

android {
        .....
        sourceSets {
            main.java.srcDirs += 'src/main/java_legacy'
            main.res.srcDirs += 'src/main/res_legacy'
        }
}

But when I try to run the app I get the error:

error: cannot find symbol variable BuildConfig 

The file where the error is shown seems random and does NOT use nor import the class BuildConfig.

If I empty the code inside the file generating the error, it appears in another (pseudo-random) file.

How can I solve this?

Note: I tried, "Build/CleanProject", "File/ Invalidate Caches / Restart ...", 'Synchronize gradle build" but the error persists

4 Answers
Related