Kunal Puri
Kunal Puri

Reputation: 185

Cannot Resolve centercrop placeholder error etc in Glide library android

Cannot Resolve centercrop placeholder error etc in Glide library android. Also tried to use glide into a new project but the problem also there. Please help I am this everything is correct or need to add something more to use Glide library.

Project build.gradel

   buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.2'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            jcenter {
                url "http://jcenter.bintray.com/"
            }
            maven  {
                url "http://repo1.maven.org/maven2"
            }
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

app-build.gradel

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.3"
        defaultConfig {
            applicationId "com.techweblearn.musicplayer"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            renderscriptTargetApi 20
            renderscriptSupportModeEnabled true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
        compile 'com.android.support:cardview-v7:25.3.1'
        compile 'com.android.support:appcompat-v7:25.3.1'
        compile 'com.android.support.constraint:constraint-layout:1.0.2'
        compile 'com.android.support:support-v4:25.3.1'
        testCompile 'junit:junit:4.12'
    }

'

Upvotes: 2

Views: 1752

Answers (1)

Mahdi Javaheri
Mahdi Javaheri

Reputation: 1250

had the same issue, after some digging found the solution
you must use Glide v4.3.0 (newer versions have some minor problems in AndroidStudio 3.0.1 for now) by doing these easy steps :

1. add this to you'r top level build.gradle

repositories {
  mavenCentral()
  google()
}

2. add dependencies to module level build.gradle

implementation 'com.github.bumptech.glide:glide:4.3.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.0'

3. add these proguard rules to your proguard-rules.pro

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
 **[] $VALUES;
 public *;
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

4. add this trivial class to your app in order to generate GlideApp class

package com.example.myapp;

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

@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

5. Clean and build your project
6. Done! now you can use GlideApp with centercrop() method

GlideApp
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .into(myImageView);

Upvotes: 1

Related Questions