Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyone know how to fix "Can't resolve symbol 'Inject'" error in Android Studio?

I'm having a problem when Android Studio v0.3.5 where the symbol 'Inject' isn't recognized.

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.

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.

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?

like image 467
Salsero69 Avatar asked Dec 26 '22 17:12

Salsero69


1 Answers

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

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:

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?

like image 96
Scott Barta Avatar answered Dec 28 '22 05:12

Scott Barta