Reputation: 40193
I tried to add a Maven dependency to my project, which uses Gradle, by adding these lines to the build.gradle file in Android Studio:
repositories {
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'org.roboguice:roboguice:2.0'
}
The project seems to compile well, but there's no way to reference Roboguice classes inside my project's code. I feel like I'm missing something, namely, how does Gradle download the dependency and where will it store it? How should I fix my project?
Upvotes: 11
Views: 21721
Reputation: 1
go to intellij preferences and enable gradle auto import dependencies
Upvotes: -2
Reputation: 3131
Using the command line, in the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new dependencies.
EDIT: At the time of the answer, Android studio didn't propose the "Gradle sync" button. It now does, so rather than using the command line, you can hit the button, and it will basically run ./gradlew clean && ./gradlew build
for you.
Anyway, it's always good to know how to do it in command line :)
The name of the button is: Sync Project with Gradle Files
See the screenshot below.
Upvotes: 21
Reputation: 39225
Nothing here worked for me. What did work was File -> Invalidate Caches / Restart...
This is an extremely annoying bug, that happens way more often that it should. The build tools should not be a hindrance to development.
Upvotes: 2
Reputation: 1595
On Android Studio I just press the Sync Project with Gradle File button, left of the AVD Manager did the job. No restart, no ./gradlew clean
or ./gradlew build
.
You can also navigate through Tools-->Android-->Sync Project with Gradle File.
Upvotes: 8
Reputation: 511
I was having the same problem. I tried all solutions suggested without success. Then I simply closed and opened again Android Studio and it worked!
Upvotes: 4