How to add the Volley library in an Android Studio project

Congratulations! Your search for “How to add Volley library to your Android Studio project” has landed you in the perfect place. This blog will be looking in detail at the same starting with some formal definitions required during the how-to and then finally moving on to the procedure itself. However, in case you are already familiar with the terms, feel free to skip to the last part of the blog. Now let’s get started without further ado.

What is the Android Studio?

Android Studio is the official Integrated Development Environment (IDE) for Android app development, based on IntelliJ IDEA. On top of IntelliJ’s powerful code editor and developer tools, Android Studio offers even more features that enhance your productivity when building Android apps.

Android Studio uses a Gradle-based build system, emulator, code templates, and Github integration to support application development within the Android operating system. Every project in Android Studio has one or more modalities with source code and resource files. These modalities include Android app modules, Library modules, and Google App Engine modules. Hence, libraries make up an integral part of an Android Studio project.

What is an external library file in Android Studio?

An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. But, instead of compiling into an APK that runs on a device, an Android library compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module.

We can use two types of libraries in our Android Studio project:

  • Android Library Module: Android Library Module compiles into an Android Archive (AAR) file that you can use as a dependency for an Android app module. It allows you to add Android-specific components like resources and manifest files, which allows you to bundle in shared resources like layouts and drawables in addition to Java classes and methods.
  • Java Library: Java library builds a Java ARchive file (JAR file). A JAR file is useful for many projects especially when you want to share code with other platforms. But it does not allow you to include Android resources or manifest files, which is very useful for code reuse in Android projects. So when you do not need any android specific resources in a library you should create a java library.

Benefits of using external libraries in your Android Studio project

Using external libraries in an Android Studio project makes things easier. The following are some of the advantages of doing so:

  • When you’re building multiple apps that use some of the same components, such as activities, services, or UI layouts, you can simply copy-paste the same libraries in your multiple apps.
  • When you are using a service whose code has already been written, you can simply add its library as opposed to writing the entire code by yourself.
  • When you’re building an app that exists in multiple APK variations, such as a free and paid version and you need the same core components in both, you can simply add the same libraries for both.

What is the Volley library and what does it do?

Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. It allows automatic scheduling of network requests and facilitates multiple concurrent network connections. Volley excels at RPC-type operations used to populate a UI, such as fetching a page of search results as structured data. It integrates easily with any protocol and comes out of the box with support for raw strings, images, and JSON. However, Volley holds all responses in memory during parsing thereby making it non-suitable for large downloads or streaming operations.

How to add the Volley library to your Android project?

Now that we have an idea of what Volley is and what can it do, let’s have a look at how can we add it to our Android Studio project. We will be looking at two ways of doing so. The Volley library can be added as a simple Gradle dependency or imported as an Android module. Although adding it as a Gradle dependency is far more quick and efficient, we shall look at both the methods.

Adding the Volley library as a Gradle dependency

Ever since Volley was officially made available on the JCenter, adding it to an Android project has become quite easy. Here’s how to do so:

  • Open the Android Studio project where you want to add the Volley library. In case you want to create a new project, create one by selecting Empty Activity.
  • Once you are inside your Android Studio project, navigate to your build.gradle file of your app.
  • To navigate to your app’s build.gradle file, make sure that your project view is set to Android and go to

    Gradle Scripts>build.gradle(Module:YourProjectName.app).

    Navigate to your app's build.gradle

  • Add the following dependency:

    implementation ‘com.android.volley:volley:1.2.0’

    Add the neccessary dependency

  • Sync your Gradle project after making the changes.
  • As Volley uses internet permission, you need to declare it in your manifest file to use Volley.
  • Navigate to your AndroidManifest.xml file in app->manifests->AndroidManifest.xml.

    Navigate to AndroidManifest.xml

  • Add the following permission:

    <uses-permission android:name=”android.permission.INTERNET” />

  • You have now successfully added the Volley library to your Android project.

Adding the Volley library as an Android Module

You can also add the Volley library to your Android Studio project by importing it as a module. To do so, we first get the latest Volley library from git as Volley is completely a git-based project. Here’s how to do so:

  • Open your command terminal and clone the Volley repository using the following command:

    git clone https://github.com/google/volley

  • Once the repository is downloaded to your PC, navigate to its location and remember the location where it is saved.
  • Next, Open the Android Studio project where you want to add the Volley library. In case you want to create a new project, create one by selecting Empty Activity.
  • Next, click on File->New->New Module…

    Create a New Module

  • Click on Import at the bottom and navigate to the previously downloaded Volley directory in the Source directory: field.

    Naviagte to the downloaded Volley repo in Source directory

  • Hit Finish and the Volley library will be imported as an Android Module.
  • Then, navigate to settings.gradle file and add or verify that the following is included:

    include ‘:app’, ‘:volley’

  • Finally, go to your app’s build.gradle and add the dependency:

    compile project(“:volley”)

  • You have now successfully added the Volley library to your Android project.

In conclusion, adding the Volley library to your project helps you make networking calls faster and easier and now we know two of the easiest ways of doing so. Hope you try them out.