"Cannot find symbol variable BuildConfig" with multiple source folders
Solution 1
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.
Solution 2
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.
Comments
-
Addev almost 2 years
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