13

i have problem with my code. My Code marked as an error code in Android Studio, but successfully build gradle and run on the device, like this : enter image description here

current configure:

  1. My current project uses a lot of libraries in dependencies. But if the project with little library will not be marked errors like this.
  2. Android Studio 1.5 RC1
  3. compileSdkVersion 'Google Inc.:Google APIs:23
  4. buildToolsVersion '23.0.2'
  5. classpath 'com.android.tools.build:gradle:1.3.1'

activity I have done but have not solved the problem:

  1. always clean > re-build project
  2. invalidate caches / restart > open Android studio > open this project
  3. Close android studio > restart computer > open again android studio > open this project
  4. Update Android version and SDK version 5.Uninstall Android Studio > Re-Install Android Studio > Open Project

edited: it's seems error each code from android support like recyclerview, CardView, APpCompact

this my depedencies

dependencies {
    compile project(':android-crop')
    compile project(':RTEditor-Toolbar')
    compile files('libs/apache-mime4j-0.6.jar')
    compile files('libs/httpmime-4.1.3.jar')
    compile files('libs/jetbrains-annotations.jar')
    compile files('libs/gcm.jar')
    //three party library
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }
    compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
        exclude module: 'support-v4'
    }
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.vinaysshenoy:mugen:1.0.1'
    compile 'com.github.clans:fab:1.5.5'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.github.chrisbanes.photoview:library:+'
    compile 'com.subinkrishna:circularimageview:1.0.2'
    compile 'me.leolin:ShortcutBadger:1.1.3@aar'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'cn.trinea.android.common:trinea-android-common:4.2.15'
    compile 'com.sothree.slidinguppanel:library:3.1.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}

so how fix ? thanks for advance

Amay Diam
  • 2,561
  • 7
  • 33
  • 57

12 Answers12

9

If your project builds in gradle, but Android Studio displays errors, chances are that the Intellij caches are corrupt. In some cases, the menu option you already mentioned "invalidate caches / restart" is not enough. You can try the following:

  1. Shutdown AS
  2. Manually delete the cache dir. On Windows, this is likely to be in a path like C:\Users\YOURNAME.AndroidStudio1.4\system\caches.
  3. Restart AS
  • it's seems error each code from android support like recyclerview, CardView, APpCompact – Amay Diam Nov 17 '15 at 08:50
  • Solved it for me after I tried invalidating the cache, deleting .idea/.gradle/iml files, restarting AS and syncing. – slai47 May 31 '19 at 18:27
  • Just burned a couple hours on this. Clearing caches finally fixed it. BTW it's 2020 and AS still has this issue! – EJK Sep 03 '20 at 05:56
6

This is extremely common, and happens to me whenever I start my Android Studio up. Follow these steps after you have made sure that you have imported everything your code needs to import. If you are not sure how to do that, look at the very bottom of my answer, where it says More Issues that could be happening.

Here are some things that you can easily do to fix it:

  • Clean project

  • Rebuild Project

  • Restart IDE

  • Update SDK tools

This is probably not an issue with your code, so you don't have to worry about it much. If cleaning and rebuilding doesn't work, just wait for some time.

Give android studio a while to set up, and this could take a few minutes. Often times, it fixes itself without even having to do any of the steps I listed above. Make sure you do this before trying to update your SDK or messing with any files. If you do that, I suggest you take a backup first.

I suggest you take a look at this question:

"cannot resolve symbol R" in Android Studio


MORE ISSUES THAT COULD BE HAPPENING

Also, according to your screenshot, I saw a lot of errors in some of the same places. This could be because you are not importing the correct things! Click on one of the pieces of code that has a red squiggly line on it, and wait for a message. It should say something about imports. Then press ALT->ENTER. This should import what you need for that line of code to work.

Community
  • 1
  • 1
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
3

None of the things mentioned earlier here did actually work for me But then I found this menu entry in the file menu Invalidate Caches/Restart which appears to have fixed the problem.

I don't really know what happened in the background but when Android Studio started up again the status bar said Indexing... for a minute or so which apparently did wonders.

if it still not working solution is very simple i have tried also

it was just go to help menu and check for update then restart android studio

as attached photo

enter image description here

mahmoud zaher
  • 544
  • 6
  • 9
1

Faced the same issue and struggled half day to resolve it.

Finally found the solution. If you're facing the situation where the project is building successfully, but Cannot resolve ThirdParty.class error is coming. Than do following steps:

  1. Delete .idea folder from your project.
  2. Close Android Studio
  3. Restart Android Studio and Import your project.

And you're good to go.

Pankaj Lilan
  • 4,245
  • 1
  • 29
  • 48
1

Tried Almost everything like invalidate catche and restart,rebuild,update sdk tools,delete .idea folder etc. but you need to delete catches manually from C:\Users\YOURNAME.AndroidStudio1.4\system\caches.It should work.

0

Adding answer from Ruchir, all the new things is good but not really good for some.

I tried to re-create my environtment and found that newest AS have problem with newest SDK. So All I did was:

  • use AS 1.4.1 (stable)
  • downgrade SDK to use v23.0.1.

gradle.build changes as follows:

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'

Then do the basics "clean up":

  • Clean project
  • Rebuild Project

Done. It's not your code, it's IDE. Consider submit error report to Google about this error.

agungandika
  • 166
  • 9
0

I got a similar problem after upgrading my PC and reinstalling Windows.

The only solution that worked for me was using jdk 7 instead of jdk 8. I never run into this problem with my old machine and jdk 8.

xKobalt
  • 1,498
  • 2
  • 13
  • 19
Andre Classen
  • 3,868
  • 3
  • 26
  • 36
0

Finally I resolved that issue just by changing JDK:

  1. Firstly right click on "Android Project", then go to "Module settings"
  2. Select "SDK Location"
  3. Uncheck "Use Embedded JDK" and browse to install "JDK" folder.
  4. Rebuild your project and all your java errors related will gone.

The cause was just the embedded JDK.

Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63
Sangharatna
  • 118
  • 7
0

I ran into the same problem many times, I tried many suggested things in StackOverflow, but I would like to share the following procedure:

1) Go to File --> Invalidate cache and restart (this worked for me most of the times)
2) Then go to Project --> App --> Right Click --> Open module settings and navigate in SDK Location, locate the java, save the settings and restart the Studio.

Hope this helped!

xKobalt
  • 1,498
  • 2
  • 13
  • 19
0

I faced the same problem and I just followed the following procedure to fix:

1) Take the backup of your android project
2) Delete it from your android studio
3) Import it again

Hulk
  • 6,399
  • 1
  • 30
  • 52
0

I'm running into this quite a bit while in the process of moving code (and libraries) from one module of a project to another.
Project compiles/runs, signed APK builds, but Android Studio editor insists it can't find classes.

In my particular scenario, the most effective solution I've found is to modify build.gradle within Android Studio such that the editor indicates:

Gradle files have changed, a Project Sync may be necessary.

Then clicking the Sync Now button. In my case, I've not actually had any reason to change the build.gradle file, so I tend to just make an arbitrary change to the file and then reverse it.

xKobalt
  • 1,498
  • 2
  • 13
  • 19
tliebeck
  • 816
  • 1
  • 8
  • 19
0

I tried most of these answers but it did not work for me, but following these steps did the magic:

  1. Click on "File" at the top left corner
  2. Click on "Repair IDE"
  3. A popup will appear at the bottom right corner with 2 options [1]: https://i.stack.imgur.com/FtXuY.png
  4. Click on "Rescan Project Indexes"
  5. If it works then its good if not than continue onto the next step

Hopefully it will help

Awais Abbas
  • 145
  • 9