2

I started working on a new app (min API: 24, target/compile: 27) yesterday and updated Android Studio to version 3.6 after creating the project. Now I keep running into the same problem over and over:

enter image description here

When I add a new UI item with an id or if I change an existing id, then access the e.g. R.id.activity1 in my code, there's no suggestion popup for the id. When I just type it out, the code turns red and it's marked as an error on the sidebar and in the class name. The app still builds and runs fine.

Contrary to this question not all of the R occurances are marked though, only the ones that I changed/created since the last restart.

What I've tried:

  • Build - Clean Project
  • Build - Rebuild Project
  • File - Sync Project with Gradle Files

Neither works. I have to restart Android Studio to get rid of the fake errors (no need to invalidate caches).

The gradle file looks fine as far as I can see (appcompat and design are version 27.1.1) and there's only a single error in the xml files that is connected to the problem:

This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.

How do I fix this, so I can actually create/edit ids without restarting Android Studio every time?

Muhamed El-Banna
  • 593
  • 7
  • 21
Neph
  • 1,823
  • 2
  • 31
  • 69
  • Have you upgraded to the latest Gradle? Also, why do you disregard the _invalidate caches_ option? That would be first on my list. Finally, although unrelated to your issue, but I think you need to target 28 now if you want to publish your app. – Nikos Hidalgo Feb 26 '20 at 16:00
  • @NikosHidalgo I'm currently on 5.6.4 (according to gradle-wrapper.properties) but there was some kind of Gradle update after updating AndroidStudio (it was a popup), so possibly. _invalidate caches_ - I just changed an id in the xml and Java code (which marked the Java one as an error), then tried that option. Now the app won't build anymore and actually prints the "cannot find symbol" error to console but even the options mentioned above or a restart won't fix it! :/ When I change the id in the code back to the original one, it builds fine, even though the xml still has he new id. – Neph Feb 27 '20 at 10:44
  • Also: Thanks for the warning. There were a couple of UI problems with the version 28 dependencies (appcompat,...) and the suggested solution was to keep using 27 for now. – Neph Feb 27 '20 at 10:47
  • After a PC restart it's now back to how it was before: Using the id of a new UI is marked as an error but the app still compiles/builds fine. Restarting Android Studio gets rid of the error for that specific id until I change it. Any idea, @NikosHidalgo? – Neph Mar 02 '20 at 14:26
  • Not sure what could be wrong. Usually, if I invalidate caches, delete the .idea files or sync project with Gradle these errors disappear. – Nikos Hidalgo Mar 02 '20 at 14:30
  • The first made it worse and the 3rd didn't change anything but what's the second thing, the ".idea" files? I didn't try that. – Neph Mar 02 '20 at 14:38
  • You close android studio completely and you find your project files in your computer. You locate the .idea folder (a hidden folder, so make sure you can see hidden files and folders), and you delete its contents and any .iml file you can fine. This is a common method for solving problems related to Android Studio settings. – Nikos Hidalgo Mar 02 '20 at 14:43
  • 1
    Thanks, I'm going to try that next time it happens. Strangely enough, renaming currently won't produce the error after restarting Android Studio once but I'm sure it won't be okay for long. – Neph Mar 02 '20 at 14:56
  • The problem reappeared today, so I followed your ".idea" advice and also deleted 2 ".iml" files (in the main project folder & in the "app" folder) but no luck: It's still marking new ids (including new `R.layout.somelayout`) as error. – Neph Mar 04 '20 at 13:21
  • Two months later and I'm using Android Studio 3.6.1 now but the problem's still there, even though it seems more random: Sometimes I'll create new e.g. `R.string.xxx` ids and get a suggestion for them in code but I still get the error too often for it not to be annoying. – Neph May 14 '20 at 08:32

0 Answers0