To add dependency using Andriod Studio GUI:
- Open File -> Project Structure… menu.
- Select Modules in the left pane, choose your project’s main module in the middle pane and open Dependencies tab in the right pane.
- Click the plus sign in the right panel, dialog will pop up.
- Enter “library name” into the search field and click the icon with magnifying glass.
- Select “the library” from the drop-down list.
- Click “OK”.
- Clean and rebuild your project.
To add dependency by editing Gradle:
Open the build.gradle (Module : app) file and paste this (at the end) :-
dependencies {
compile “com.android.support:appcompat-v7:21.0.+”
}
Note that this dependencies is different from the dependencies inside buildscript in build.gradle (Project)
When you edit the gradle file, a message shows that you must sync the file. Press “Sync now”
Adding Support Libraries
To add a Support Library to your application project (same as above):
- Open the build.gradle file for your application.
- Make sure that the repositories section includes a maven section with the “https://maven.google.com” endpoint. For example:
allprojects {
repositories {
jcenter()
maven {
url “https://maven.google.com”
}
}
} - Add the support library to the dependencies section. For example, to add the v4 core-utils library, add the following lines:
dependencies {
…
compile “com.android.support:support-core-utils:25.3.1”
}
References :- Support Library Setup