“Cannot resolve symbol” for all classes from external library in Intellij

孤人 提交于 2021-02-05 08:38:05

问题


I have an Intellij project that uses Gradle. I've added an external dependency in the form of a JAR file in the libs folder, and added it to build.gradle using this:

compile fileTree(dir: 'libs', include: '*.jar')

Intellij recognizes it as a dependency, since it allows me to browse the file and view its contents, plus it suggests the packages I can import.

However, I can't use any of the classes contained. Intellij says Cannot resolve symbol '[classname]'. This occurs in both the library itself and my project files.

Other Gradle dependencies work fine, like those in the form compile "some.group:artifact:version".

I've tried all of the fixes I've found online for this, including:

  • Invalidating Cache/Restarting
  • Deleting the .idea file

How can I use this local JAR file as a dependency?


回答1:


It looks like the jar you've attached contains *.java files instead of the compiled *.class files.

Library dependencies will work only for the jars with the .class files. Find a library jar instead of the source jar for this dependency and place it to the libs directory, reimport the project.



来源:https://stackoverflow.com/questions/63000680/cannot-resolve-symbol-for-all-classes-from-external-library-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!