add dependencies, how to add gradle in android studio, android gradle dependencies, android dependencies list, gradle dependencies implementation

How to add dependencies for Android in Android studio

During your android development journey, you may notice that there are some of the libraries you want to include in your project but they are not available in android studio. These libraries are dependent on every project and vary depending on what you want to achieve. Please note there are some libraries that are default in every project that is mostly predefined by android when you create your project.

What are Dependencies in Android Studio?

Dependencies are that external items are made by other developers but are acceptable by android to perform a certain task. Dependencies allow one to include external libraries or other library modules in the Android project. For example, while you want to display an image in your project app, you can add a library called Picasso or Glide Library to help you achieve this.

Dependencies are helpful since they make your work easier since you will just include it and start using the classes and functions without having to think of how it is created.

To know how to add dependencies in android studio;

  1. Ensure your android studio is well installed and setup, (click this article to download and install android studio Download and install android studio )
  2. Create and set up your project (follow this link to create your android application Create Android Project )

In the android studio, you will find Gradle scripts in the app section in the left side pane of the android studio

You will notice there are two build.gradle files one for project and one for module, the one for project is the Top-level build file where you can add configuration options common to all sub-projects/modules. The module gradle file is where we add libraries that involves individual modules, for example, a library that is only used in the login page but it has no relation to the main activity page.The module build.gradle is the one that is commonly used
How to add dependencies for Android in Android studio
  • Open the build.gradle file
  • Locate the library you want to use in the browser (mostly these libraries are available in GitHub)
  • In this case, let's add the Picasso library
  • The link to the GitHub Picasso library is as follows https://github.com/square/picasso
  • Scroll down to the download section
How to add dependencies for Android in Android studio
  • Copy the implementation line
implementation 'com.squareup.picasso:picasso:2.71828'
In your build.gradle file for Module, add the above implementation file in the dependencies section as follows
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}

How to add dependencies for Android in Android studio

Click the sync now button at the top right so that it can fetch the library files and add it into your projectWait for the process to finish by monitoring the progressOnce it’s done, you can now add codes related to the library you have added in your modules In our example above, the full build.gradle file code is as below
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.solutionspaceapp"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
With the discussion we have had of how to add dependencies for android in android studio, you can follow the same to add any library you want in your project.