Java 任何人都知道如何修复 Android Studio 中的“无法解析符号‘Inject’”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19985971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Anyone know how to fix "Can't resolve symbol 'Inject'" error in Android Studio?
提问by Salsero69
I'm having a problem when Android Studio v0.3.5 where the symbol 'Inject' isn't recognized.
当 Android Studio v0.3.5 无法识别符号“Inject”时,我遇到了问题。
I have the following: import javax.inject.Inject;
where the whole line is greyed out except for Inject where it's red. The greyed out part gives me a hint that it's an unsused import, but the red part gives me a cannot resolve symbol error.
我有以下内容:import javax.inject.Inject;
除了 Inject 是红色的,整条线都是灰色的。灰色部分提示我这是未使用的导入,但红色部分提示我无法解析符号错误。
So I followed the instruction here-> Android Studio: Add jar as library?, but without any success. I get the following error when I do a gradlew clean
.
所以我按照这里的说明-> Android Studio: Add jar as library? ,但没有任何成功。当我执行gradlew clean
.
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\dovailla\AndroidStudioProjects\BootstrapProject\build.gradle' line: 2
* What went wrong:
A problem occurred evaluating root project 'BootstrapProject'.
> Could not find method compile() for arguments [file collection] on root project 'BootstrapProject'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.093 secs
Anyone have a clue?
有人有线索吗?
回答by Scott Barta
javax.inject isn't part of the Android Java library, so you'll need to pull that in from an external library. You might find some more help at Android Roboguice Exception
javax.inject 不是 Android Java 库的一部分,因此您需要从外部库中提取它。您可能会在Android Roboguice Exception 中找到更多帮助
Note that the answers there tend to have you download a jar, put it in your libs directory, and access it that way; you may find it more convenient to use a Maven-style dependency declaration, similar to:
请注意,那里的答案往往让您下载一个 jar,将其放入 libs 目录中,然后以这种方式访问它;您可能会发现使用 Maven 风格的依赖声明更方便,类似于:
dependencies {
...
compile 'javax.inject:javax.inject:1@jar'
}
Looking at the error message from your build, I think it's a syntax error in your build.gradle file -- did you put your compile files(...)
statement in your dependencies
block?
查看来自您的构建的错误消息,我认为这是您的 build.gradle 文件中的语法错误——您是否将您的compile files(...)
语句放在您的dependencies
块中?