Question

I am just starting to work on android studio and beginning to explore the world of Gradle. So I created a project in Android Studio, opened up build.gradle and added dependencies like the below:

dependencies {
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.squareup.retrofit:retrofit:1.3.0'
    compile 'com.jakewharton.timber:timber:2.1.0'
}

After this I notice a tip popping up on build.gradle which says:

You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation"

I ignore this and I don't find either timber or retrofit in the external libraries after I try building the project. Obviously I was missing something. I believed that after declaring the dependencies and clicking build, the particular libraries will be auto imported but yes, I was wrong.

So I agree and apply the tip which popped up on build.gradle and then the project got refreshed, post which all the dependencies were available in the "External Libraries".

So the question is:

  • How do I ensure to have all the dependencies in place after declaring it in build.gradle?

I have read that I can do this the GUI way by clicking on import modules but I want to find out if there are other ways

Was it helpful?

Solution

If you're not using Android Studio 0.4.3, please upgrade to it -- there are bugfixes in that version that prevent newly-added dependencies from being completely visible to your project in the IDE (though it would actually build okay). If you're not already running 0.4.3, that will probably fix your problem.

As for the message about configuring the Gradle wrapper to use sources, that applies to having the wrapper download a version of Gradle itself that includes the source code to Gradle. Doing this allows the IDE to be smarter about syntax highlighting when you're editing build.gradle files from the IDE. What that tip does is it changes this URL in your gradle/wrapper/gradle-wrapper.properties file from this:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip

to this:

distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip

OTHER TIPS

Yo can check your dependencies from Android Studio GUI using following steps :

  • Go to to File > Project Structure or Right click on project and choose Open Module Settings
  • Opened window will have all your modules listed in left side pane and some tabs on right pane.
  • Select the module for which you want to check the Dependencies and choose "Dependencies" tab from Right pane.

You will see all dependencies there which you have defined in your build.gradle file, also using "+" icon available on right pane you can add more.

Dependencies GUI

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top