AndroidAndroid UI

Android Tutorial – Glide V4 Implementation

Glide is a widely popular, fast and memory efficient image loading library for Android. Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.

In the context of image loading also, there are many popular third party libraries for loading and Glide is the most popular among them.

The latest version of Glide library is Glide v4 and it requires API 14 or higher. 4th version is much faster and efficient for image loading and it is highly recommended to use the latest version.

Here i will explain about a sample implementation of Glide v4 library by loading an image from live URL.

Android SDK Requirements

  • Minimum SDK Version – 14 or higher.
  • Compile SDK Version – 26 or higher.

Add Internet permission In Manifest

Add Internet Permission.

<!-- Internet Permission --> <uses-permission android:name="android.permission.INTERNET" />


Add Dependencies Into build.gradle

* Add mavenCentral() repository for Glide.
* Add 2 lines of dependency code.

apply plugin: ''

repositories {
    maven { url '' }

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId ""
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner ""
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('', {
        exclude group: '', module: 'support-annotations'
    compile ''
    compile ''

    //Add following 2 lines of code
    compile 'com.github.bumptech.glide:glide:4.1.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.1.1'

    testCompile 'junit:junit:4.12'

Create AppGlideModule Class

As per the official document, The API is only generated when a properly annotated AppGlideModule is found. There can only be one AppGlideModule per application.

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

 * Created by on 8/9/17.

public class SampleGlideModule extends AppGlideModule {

Add Few Lines To

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;

MainActivity Class

Just inflate the ImageView and load the image into it using GlideApp in the onCreate() of the activity.

import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestListener;

 * Created by on 8/9/17.

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        //The target image
        ImageView imageView = (ImageView) findViewById(;

        String path = ""; // Replace the url here

                .transition(DrawableTransitionOptions.withCrossFade()) //Optional
                .skipMemoryCache(true)  //No memory cache
                .diskCacheStrategy(DiskCacheStrategy.NONE)   //No disk cache
                .listener(new RequestListener() {
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
                        return false;

                    public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
                        return false;

Activity XML

Add a ImageView to which image is going to be loaded.

<!--?xml version="1.0" encoding="utf-8"?-->

< xmlns:android="" xmlns:app="" xmlns:tools="" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="">

<imageview android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginbottom="0dp" android:layout_marginleft="0dp" android:layout_marginright="0dp" android:layout_margintop="0dp" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" app:srccompat="@mipmap/ic_launcher">

Note: If GlideApp is not resolved then rebuild the entire project after completing all the above steps.


About author

Rojer is a programmer by profession, but he likes to research new things and is also interested in writing. Devdeeds is his blog, where he writes all the blog posts related to technology, gadgets, mobile apps, games, and related content.

Leave a Reply

Your email address will not be published. Required fields are marked *