【问题标题】:Cannot Resolve centercrop placeholder error etc in Glide library android无法解决 Glide 库 android 中的 centercrop 占位符错误等
【发布时间】:2019-03-25 00:45:22
【问题描述】:

无法解决 Glide 库 android 中的 centercrop 占位符错误等。 还尝试使用 glide 进入一个新项目,但问题也存在。 请帮助我,这一切都正确或需要添加更多内容才能使用 Glide 库。

项目构建.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'
    }

'

【问题讨论】:

  • 堆栈跟踪或编译错误在哪里?
  • 我遇到了同样的问题。到目前为止,我发现的唯一解决方案是将 Glide 版本降级为 com.github.bumptech.glide:glide:3.8.0

标签: java android android-glide


【解决方案1】:

遇到了同样的问题,经过一番挖掘找到了解决方案
您必须通过执行以下简单步骤来使用 Glide v4.3.0(较新版本目前在 AndroidStudio 3.0.1 中存在一些小问题):

1. 将此添加到您的顶级 build.gradle

repositories {
  mavenCentral()
  google()
}

2。将依赖项添加到模块级 build.gradle

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

3。将这些 proguard 规则添加到您的 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。将这个琐碎的类添加到您的应用中以生成 GlideApp 类

package com.example.myapp;

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

@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

5。清理并构建您的项目
6. 完成!现在你可以使用带有 centercrop() 方法的 GlideApp

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

【讨论】:

    猜你喜欢
    • 2014-11-14
    • 1970-01-01
    • 2017-12-24
    • 2021-05-07
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多