问题
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