Android Studio says “cannot resolve symbol” but project compiles –

Development issue/problem:

I import twitter4j into AndroidStudio with the following in my build.gradle:

Dependencies {
compiles ‘com.android.support:support:v4:18.0.+’
compiles files (‘libs/twitter4j-core-3.0.4.jar’)
}

The project is well put together and I can create tweet objects without any problems. In Android Studio, however, anything pointing to the library will not resolve the icon and it will appear in red. How do I make sure Android Studio recognizes the library?

I’ve already tried to repair, clean up, close and reopen the project.

How can I solve this problem?

Solution 1:

I don’t know if it’ll work, but so far my only thought is this: Right-click on the pot file in the file structure in AS and select Add as Library……

EDIT: You can choose File -> Invalid Cache… and select Invalid and restart to correct it.

EDIT 2 : This patch should work for all these incidents and is not a twitter4j specific patch.

Solution 2:

Try changing the order of the dependencies in File > Project structure > (Select Project) > Dependencies.

Invalid Cache didn’t work for me, but moving my test from the bottom of the list to the top did.

Solution 3:

That’s what worked for me.

In the Project window, right-click on the project name and choose
Module settings from the drop-down menu.

Then change the SDK version to the minimum available version (the minimum version of the sdk you have installed in the project).
waits until android studio has downloaded everything.

That gives you some mistakes, ignore them.

Now navigate to your Java file and android studio will ask you to import it.

import android.support.v4.app.FragmentActivity ;

Import it, then go back to the Open Module Settings and change the compiled sdk version back to the previous one.

Wait till it’s all loaded and there you go.

Solution 4:

For me it is caused by an imported library project, put something in build.gradle and delete it again and now click sync, the error is gone.

Solution No 5:

I also had this problem with my Android application, which depends on some of my own Android libraries (using Android Studio 3.0 and 3.1.1).

Every time I updated the library and returned to the application by running Gradle Sync, Android Studio couldn’t detect the code changes I had made in the library. The compilation worked well, but Android Studio showed red fault lines on some codes with lib.

After research I found out that it’s because Gradle points to an old composite version of my libraries.
If you go to your project/.idea/librarys/, you will see a list of xml files that contain a link to the compiled version of your libraries. These files start with Gradle__artifacts_*.xml (where * is the name of your libraries).

So, in order for Android Studio to take the latest version of your libraries, you need to delete these Gradle__artifacts_*.xml files and Android Studio will restore them and refer to the latest compiled version of your libraries.

If you don’t want to do it manually every time you press the Gradle Sync button (who would want that?), you can add this little task to your application’s build.gradle file.

task delletheartifacts {
doFirst {
FileFolderPath = file(getProjectDir().absolutePath + /../.idea/librarys/)
File[] files = librariesFolderPath.listFiles({ File -> file.name.startsWith(Gradle__artifacts_) } as FileFilter)

for (int i = 0; i

And to make sure that your application always performs this task before Gradle synchronization, just go to the Gradle window and find the deleteArtifacts task under yourArr/Tasks/others/, right click on this task and select Execute Before Sync (see below).

From now on Android Studio is required to use the latest version of your libraries every time you synchronize Gradle.

Solution No 6:

When I got this problem (red color codes, but they work well) in my ;

As before, I did this (File -> Specify Caches) –> (Invalid and Restart).

I finally resynced my build.gradle file in my application. After the problem is solved.

Solution No 7:

Invalid Cache / Restart did not work this time.

I’ve found this solution:

  1. Remove the *** build line or *** implementation line in build.gradle.
  2. Beauty and restoration. Errors must be corrected here.
  3. Paste the line from step 1 into build.gradle.
  4. Beauty and restoration.

Strange…

Solution No 8:

I encountered this problem when my Glasproject did not use the SDK installed as standard in Android Studio. I used a different location where I used to have ADT because I wanted to avoid having to charge everything. After returning the project to the SDK at the installation site of the Android Studio, the problem is gone.

Solution No 9:

I had this problem for a few days, and I finally found a solution!
All the other options didn’t work for me.

Solution: I brought special characters for this project!

Just make sure you don’t have them and that everything is in order, or at least one of the other solutions works for you.

I hope that helps somebody!

Solution No 10:

I recently had the same problem with Android Studio 1.3. The only possible solution was to remove the .gradle and .idea folders and reimport the project into Android Studio.

Good luck!

cannot resolve symbol r after cleaning,android studio package r does not exist,cannot resolve symbol xml android studio,what is r android studio,cannot resolve symbol r in android studio,cannot resolve symbol id in android studio,cannot resolve symbol builder java,cannot resolve symbol in intellij,cannot resolve symbol t android,cannot resolve symbol activity android studio,android studio cannot resolve symbol layout,error in cannot resolve type entity to symbol,gradleexception(flutter sdk not found),unresolved reference: flutteractivity,android studio project settings,android studio invalidate caches,update settings gradle flutter,cannot resolve symbol gradleexception flutter,android studio cannot resolve symbol,module not found error can t resolve android studio,cannot resolve symbol java android studio,cannot resolve symbol build android studio,android studio cannot resolve symbol activity xml,cannot resolve method android studio,cannot resolve symbol string android studio

You May Also Like