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.
If nothing else helped, you could do as Android Studio suddenly cannot resolve symbols recommends:
It happened to me when I removed the whole files in
.gradle/caches
, then studio downloaded the dependences. The dependences not showed in theExternal Libraries
but I can build App successfully.rebuild
clean
Invalidate and Restart
have no effect. I solved the problem by the steps:.idea
package in your projectFor mine was caused by the imported library project, type something in build.gradle and delete it again and press sync now, the error gone.
Invalidate Caches / Restart
didn't work for me this time.Found a solution like this:
Remove the
compile ***
orimplementation ***
line in build.gradle.Clean and rebuild. Errors should be raised here.
Add the line in step 1 back to build.gradle.
Clean and rebuild.
Weird...
Invalidate Caches didn't work for me (this time). For me it was enough changing the gradle and syncing again. Or https://stackoverflow.com/a/29565362/2000162
For my case working with AndroidStudio 2.2.3 the solution was to change the gradle wrapper/distribution to use local one in the Gradle Settings (despite of being "recommended").