Android Studio cannot resolve symbol but code executes correctly

前端 未结 9 2014
误落风尘
误落风尘 2020-11-27 04:06

I have recently created a library Jar file that I imported in my Android project. I am able to call functions and use classes that are present in this Jar file, but Android

相关标签:
9条回答
  • 2020-11-27 04:50

    This was always happening to me after switching branches on my current project: a lot of non-sense erros being reported by the IDE.

    The solution is to modify and force a build.gradle synchronization.

    0 讨论(0)
  • 2020-11-27 04:51

    This worked for me:

    Go to File -> Sync Project with Gradle Files.

    0 讨论(0)
  • 2020-11-27 04:52

    Try adding the library to the Project Structure.

    To do this, on the menu choose File -> Project Structure. Select the Libraries option and click the green + to add your library.

    0 讨论(0)
  • 2020-11-27 04:53

    Try following steps:

    1. Close your project then in your project folder delete project /.idea
    2. Delete /.gradle folder also
    3. Noe choose File option from menu on left top side of android studio
    4. Select the option: Invalidate Cache/Restart It will open a dialog
    5. Click on the first button with option: Invalidate and Restart

    After trying above options everything should be working fine.

    0 讨论(0)
  • 2020-11-27 04:55

    I found the issue - my SDK.jar was not generated correctly. It included .java files instead of .class files. This explains why the IDE was not able to find the SDK class. The package structure was still correct in the Jar, which is why the package name itself is not a red color. The code worked correctly, because the compiler knew to compile the .java files.

    To solve the issue, I modified my build.gradle of my SDK project to include .class files, instead of .java files, when creating the Jar. Including this new Jar instead of the old Jar fixed the IDE issue.

    EDIT: For most folks, Senthil's answer will be more appropriate. I am leaving this one as the accepted answer because it solved my specific problem.

    0 讨论(0)
  • 2020-11-27 04:57

    This problem regularly generated in android 3.1. I have tried every possible way. But it resolved when i delete .gradle and .idea file and start Android studio which is already close.

    Android studio create .idea and .gradle file for your project again. After this click on sync project with gradle. Now everything works fine.

    0 讨论(0)
提交回复
热议问题