Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.1: Erroneous unresolved references in editor

I'm running Ubuntu 17.10, and I've just updated Android Studio from version 3.0.1 to 3.1. Here's the version information in Help -> About:

Android Studio 3.1 Build #AI-173.4670197, built on March 22, 2018 JRE: 1.8.0_152-release-1024-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.13.0-37-generic 

Unfortunately, while the IDE was able to resolve android-specific references before in my (first ever) Kotlin project, in the new version it appears unable to. Here's a screenshot showing what I mean:

In Android Studio 3.1, it's claiming that core Android functions such as setContentView() don't exist, and keeps prompting me to create an abstract function for it - which I clearly don't want to do. However, if I hit the build button, I get a BUILD SUCCESSFUL in 8s.

Why is my editor doing this, and how I get get Android-related functions and classes to resolve correctly again?

  • Build → Clean and then Build → Rebuild doesn't help.
  • File → Invalidate Caches and Restart doesn't help either
  • Neither does a manual Gradle sync.
  • A different project that's written in Java instead of Kotlin works fine.
  • Link to the project I'm experiencing issues with (it's open-source)
like image 734
starbeamrainbowlabs Avatar asked Mar 28 '18 22:03

starbeamrainbowlabs


People also ask

What does unresolved reference mean in Android Studio?

To conclude, the unresolved reference error happens when Kotlin has no idea what the keyword you're typing in the file points to. It may be a function, a variable, or another construct of the language that you've yet to declare in the code.


2 Answers

  1. Exit Studio.
  2. Delete .idea/ (seems to me that's most important), build/, app/build directories.
  3. Start Studio
  4. Set Settings -> Build -> Gradle settings back (last stable Gradle local distribution in my case).
  5. Clean&rebuild project.

Helps me.

like image 79
Slava Glushenkov Avatar answered Sep 27 '22 18:09

Slava Glushenkov


Delete {projectDir}/.idea/libraries, then go to File -> Sync Project with Gradle Files.

like image 30
VikingBadger Avatar answered Sep 27 '22 18:09

VikingBadger