问题描述
我有一个使用Gradle的Intellij项目.我在 libs
文件夹中以 JAR
文件的形式添加了一个外部依赖关系,并使用以下方式将其添加到 build.gradle
中:
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将其识别为依赖项,因为它允许我浏览文件并查看其内容,并建议我可以导入的软件包.
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.
但是,我不能使用其中包含的任何类.Intellij说无法解析符号'[classname]'
.在库本身和我的项目文件中都会发生这种情况.
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.
其他Gradle依赖项可以很好地工作,例如以 compile"some.group:artifact:version"
的形式.
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:
- 使缓存/重新启动无效
- 删除
.idea
文件
如何使用此本地 JAR
文件作为依赖项?
How can I use this local JAR
file as a dependency?
推荐答案
您所连接的jar似乎包含 *.java
文件,而不是已编译的 *.class
文件.
It looks like the jar you've attached contains *.java
files instead of the compiled *.class
files.
库依赖项仅适用于具有 .class
文件的jar.为该依赖关系找到一个库jar而不是源jar,并将其放置在 libs
目录中,重新导入项目.
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.
这篇关于“无法解析符号"适用于Intellij外部库中的所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!