A few days ago, I accepted a contract from a returning client to make a few changes to his Android app over the course of the next few weeks. After getting the project source code from Github, I imported it into Android Studio (3.2) and noticed an error that I usually see pretty frequently but only for a short time during a Gradle sync: error: package R does not exist
. Naturally, I shrugged my shoulders and ran 'Clean Project' and then 'Make Project.'
Nothing changed
Did a quick Google search and tried every 'solution' I could find. I tried every combination of "Make Project", "Make Module", "Clean Project", "Rebuild Project", "Sync Project with Gradle Files", "Sync with File System", "Invalidate Caches/Restart" imaginable. I restarted my laptop, updated SDK files, updated build tools, singled out each and every Gradle 'Implementation' line, and finally ended up uninstalling/reinstalling Android Studio as well as deleting all my IDE preferences just in case.
Still nothing
Next, I created a new project and noticed that the generated setContentView()
line had the same error referencing the generated layout file. Wait. An untouched new project is having the same error?!? I went ahead and pressed 'run' and the project compiled without any errors contrary to what the real-time inspections are saying.
Switching back over to the original imported project, I tried running it and the compiler gives the same R package error. WHY?!?! There aren't any other errors, Android Lint runs cleanly, my Gradle implementations are recognized in the files, package names are all correct, and my AndroidManifest.xml file is perfectly fine.
If you need to see my build.gradle files, AndoridManifest, or anything else, comment and let me know.
Any ideas?
EDIT
Not a duplicate because as I mentioned, I've tried all of those solutions and none worked. I explained what I've tried, and why it's a unique situation.
Compare the contents of your build folder to mine and you should notice the difference:
Notice that the R folder in the upper image is marked differently? That's a working one. The lower image shows the broken project. These were taken moments apart.