Android Studio cannot find my resources
Try add the following under defaultConfig (within android {...})
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
If you are having this problem in current Android Studio version, or something to the same extent (E.g. I added images to my drawable folder, and they were not recognized) your problem may be what I encountered.
If you ran into this problem after duplicating a project you were working on, then this new project was likely not imported correctly.
I made the mistake of copying and pasting the project in the IDE, renaming it (editing manifest), then trying to work on it. This will not work, because the new project is still accessing the original's res folder.
When duplicating a project, so as not to ruin your original you should:
- Go to your Android Studio project folder (Right click on your current project in the IDE, and select "Show In Explorer".
- Copy + Paste this project in the same directory; renaming folder accordingly to new version name.
- In IDE go to File > Import Project > ... And locate the directory of your new project.
- (Proceed to rename project in IDE accordingly. Change the package name in AndroidManifest.xml)
This way the IDE creates a new project for it, and it access the correct res folder (not that of the original).
Though this may not be the solution to many of you reading this question; I came across this question many times prior to discovering the proper way to duplicate a project.
I hope this can save someone some time.