Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Cannot find symbol variable BuildConfig" with multiple source folders

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

like image 938
Addev Avatar asked Mar 10 '16 12:03

Addev


2 Answers

I had this problem and it turned out I had two directories in src/main/java/com/<app name> - one was old and didn't match the bundle id. Removing this fixed the problem for me.

like image 115
TimL Avatar answered Oct 04 '22 03:10

TimL


This might help others who wasted few hours resolving a similar issue. Search for occurrences of BuildConfig and see if the right one has been imported. Strangely the compiler didn't catch an obvious wrong import but pointed at a random line of code.

like image 28
RRK Avatar answered Oct 04 '22 05:10

RRK