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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With