Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio says "cannot resolve symbol" but project compiles

I'm importing twitter4j in AndroidStudio, using the following in my build.gradle:

dependencies {   compile 'com.android.support:support-v4:18.0.+'   compile files('libs/twitter4j-core-3.0.4.jar') } 

The project compiles fine, and I can create twitter objects without a problem. However, in Android studio, anything referencing that library shows "cannot resolve symbol" and displays in red. What do I need to do to get Android Studio to recognize the library?

I have already tried rebuilding the project, ./gradlew clean, and closing and re-opening my project.

like image 678
TG-T Avatar asked Oct 22 '13 03:10

TG-T


People also ask

What does Cannot resolve symbol mean?

In JavaLanguage, if you get 'cannot resolve symbol', you have used a name that the compiler hasn't recognized. Class names -- If it is a class name, the compiler cannot find the class.

How do I fix resolve Cannot resolve symbol in Intellij?

First of all you should try File | Invalidate Caches and if it doesn't help, delete IDEA system directory. Then re-import the Maven project and see if it helps.


Video Answer


1 Answers

No idea if this will work or not but my only thought so far: right click the jar file in file tree within AS and select "Add as library..."

EDIT: You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.

EDIT 2: This fix should work for all similar incidents and is not a twitter4j specific resolution.

like image 177
doydoy Avatar answered Oct 21 '22 13:10

doydoy