Marked as an error code in Android Studio, but successfully build gradle and run on the device

If your project builds in gradle, but Android Studio displays errors, chances are that the Intellij caches are corrupt. In some cases, the menu option you already mentioned "invalidate caches / restart" is not enough. You can try the following:

  1. Shutdown AS
  2. Manually delete the cache dir. On Windows, this is likely to be in a path like C:\Users\YOURNAME.AndroidStudio1.4\system\caches.
  3. Restart AS

This is extremely common, and happens to me whenever I start my Android Studio up. Follow these steps after you have made sure that you have imported everything your code needs to import. If you are not sure how to do that, look at the very bottom of my answer, where it says More Issues that could be happening.

Here are some things that you can easily do to fix it:

  • Clean project

  • Rebuild Project

  • Restart IDE

  • Update SDK tools

This is probably not an issue with your code, so you don't have to worry about it much. If cleaning and rebuilding doesn't work, just wait for some time.

Give android studio a while to set up, and this could take a few minutes. Often times, it fixes itself without even having to do any of the steps I listed above. Make sure you do this before trying to update your SDK or messing with any files. If you do that, I suggest you take a backup first.

I suggest you take a look at this question:

"cannot resolve symbol R" in Android Studio


MORE ISSUES THAT COULD BE HAPPENING

Also, according to your screenshot, I saw a lot of errors in some of the same places. This could be because you are not importing the correct things! Click on one of the pieces of code that has a red squiggly line on it, and wait for a message. It should say something about imports. Then press ALT->ENTER. This should import what you need for that line of code to work.


None of the things mentioned earlier here did actually work for me But then I found this menu entry in the file menu Invalidate Caches/Restart which appears to have fixed the problem.

I don't really know what happened in the background but when Android Studio started up again the status bar said Indexing... for a minute or so which apparently did wonders.

if it still not working solution is very simple i have tried also

it was just go to help menu and check for update then restart android studio

as attached photo

enter image description here