Android Studio says "cannot resolve symbol" but project compiles

This is what worked for me.

In the Project panel, right click on the project name, and select Open Module Settings from the popup menu.

then change the Compile SDK Version to the minimum version available (the minimum sdk version you set in the project). wait for android studio to load everything.

It will give you some errors, ignore those.

Now go to your java file and android studio will suggest you import

import android.support.v4.app.FragmentActivity;

Import it, then go back to Open Module Settings and change the compile sdk version back to what it was before.

Wait for things to load and voila.


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.


For mine was caused by the imported library project, type something in build.gradle and delete it again and press sync now, the error gone.


Try changing the order of dependencies in File > Project Structure > (select your project) > Dependencies.

Invalidate Caches didn't work for me, but moving my build from the bottom of the list to the top did.