Glide因为4.3.1版本的Context而崩溃。

8
在新版本的Glide 4.3中,我尝试使用它,但是无论我传递给它什么上下文,它都会崩溃。以下是显示给我的错误信息:
   java.lang.AbstractMethodError: abstract method "void com.bumptech.glide.module.RegistersComponents.registerComponents(android.content.Context, com.bumptech.glide.Glide, com.bumptech.glide.Registry)"

这是我的代码,我尝试了:

Glide.with(getApplicationContext()).
            load(url)
            .into(imageView);

and

   Glide.with(getContext()).
            load(url)
            .into(imageView);

它向我发出了警告

W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored

在Gradle中的lib文件夹中的代码
compile 'com.github.bumptech.glide:glide:4.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'

更新1: 通过添加一个继承自AppGlideModule的类来解决警告问题。

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

@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

但是相同的错误仍然存在。

1
如果在任何库的build.gradle文件中添加了annotationProcessor,请尝试将其添加到应用程序的build.gradle文件中,否则请查看此链接https://github.com/bumptech/glide/issues/2243。 - Navneet Krishna
你是否已经添加了以下内容到项目仓库中? repositories { mavenCentral() maven { url 'https://maven.google.com' } } - hemen
2个回答

7
请在您的AppGlideModule类中添加以下方法。
@Override
public boolean isManifestParsingEnabled() {
  return false;
}

为了与Glide v3的GlideModules保持向后兼容性,Glide仍然解析应用程序和任何包含的库的AndroidManifest.xml文件,并将包括在清单中列出的任何旧版GlideModules。虽然这个功能将在未来版本中被移除,但我们目前保留了这个行为以便于过渡。 如果您已经迁移到Glide v4的AppGlideModule和LibraryGlideModule,您可以完全禁用清单解析。这样做可以提高Glide的初始启动时间,并避免尝试解析元数据时可能出现的一些问题。要禁用清单解析,请在您的AppGlideModule实现中覆盖isManifestParsingEnabled()方法。
参考:http://bumptech.github.io/glide/doc/configuration.html

1
谢谢你,这节省了我几个小时的时间,因为我整天都在寻找它。 - Sattar

1

对于像我这样来到这里并花费两天时间弄清楚AppGlideModule在哪里的人,我为那些人写下了这篇文章。你必须在你的应用程序中创建一个类,并将其命名为"MyAppGlideModule",然后你应该将这段代码放入该类中。

package com.arash;


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

@GlideModule
    public final class MyAppGlideModule extends AppGlideModule {
        @Override
        public boolean isManifestParsingEnabled() {
            return false;
        }
    }

就是这样。


1
只有一个注释:它不一定是MyAppGlideModule,可以取任何名称:重要的是注解和实际定义。 - kingston

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接