To add dependency using Andriod Studio GUI:

  1. Open File -> Project Structure… menu.
  2. Select Modules in the left pane, choose your project’s main module in the middle pane and open Dependencies tab in the right pane.
  3. Click the plus sign in the right panel, dialog will pop up.
  4. Enter “library name” into the search field and click the icon with magnifying glass.
  5. Select “the library” from the drop-down list.
  6. Click “OK”.
  7. 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):

  1. Open the build.gradle file for your application.
  2. 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”
            }
        }
    }
  3. 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