Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying Maven dependencies in build.gradle doesn't work

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?

like image 917
Egor Avatar asked May 30 '13 16:05

Egor


2 Answers

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.

like image 152
Christopher Perry Avatar answered Oct 21 '22 01:10

Christopher Perry


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.

enter image description here

like image 21
lukas Avatar answered Oct 21 '22 00:10

lukas