Easy way to add the Glide library in Android Studio
If you were surfing the web to search how to add the Glide library to your Android Studio project, look no more. Your search for “How to add Glide library to your Android Studio project” has landed you in the perfect place. This blog will be looking in detail, 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 Glide library and what does it do?
Glide is a fast and efficient open-source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface. Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug into almost any network stack. By default, Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug into Google’s Volley project or Square’s OkHttp library instead.
Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.
How to add the Glide library to your Android project?
Now that we have an idea of what Glide is and what it can do, let’s look at how we can add it to our Android Studio project. We will be looking at two ways of doing so. The Glide 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 methods.
Adding the Glide library as a Gradle dependency
Ever since Glide 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 Glide 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).
-
Add the following dependency:
implementation ‘com.github.bumptech.glide:glide:4.11.0’
-
If you plan on using integration libraries along with Glide and configuring it, add the following dependency too along with the previous one:
annotationProcessor ‘com.github.bumptech.glide:compiler:4.11.0’
-
In the repositories, add the following dependency:
maven { url ‘https://maven.google.com’ }
- Sync your Gradle project after making the changes.
- As Glide 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.
-
Add the following permission:
<uses-permission android:name=”android.permission.INTERNET” />
- You have now successfully added the Glide library to your Android project.
Adding the Glide library as an Android Module
You can also add the Glide library to your Android Studio project by importing it as a module. To do so, we first get the latest Glide library from git as Volley is completely a git-based project. Here’s how to do so:
- Download the latest version of Glide as a JAR file from here.
- Once the JAR file is downloaded to your PC, navigate to its location and remember the location where it is saved.
-
Once you are in your project, change the project view from Android to Project Files.
-
Copy the JAR file of the library that you want to add. Here, we will copy the downloaded Glide JAR file.
-
Once you have copied the Glide JAR file, navigate to the libs folder by going to app->libs in the Project Files view.
-
Right-click on the libs folder and hit Paste.
-
Right-click on the pasted JAR file and select Add As Library… from the drop-down menu.
- You have now successfully added the Glide library to your Android Studio project.
-
You can change back the project view to Android and navigate to your build.gradle file to see that your external library is now included in it.
- It’s that simple.
In conclusion, adding the Glide library to your project helps you make networking calls to images faster and easier and now we know two of the easiest ways of doing so. Hope you try them out.