Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...