美文网首页
Glide升级到4.x版本遇到的问题

Glide升级到4.x版本遇到的问题

作者: 汪和呆喵 | 来源:发表于2018-12-25 22:15 被阅读0次

    今天使用glide版本加载在线图片,遇到两个问题

    Failed to find GeneratedAppGlideModule报错:

    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.
    依赖的glide版本是

        // glide
        implementation ('com.github.bumptech.glide:glide:4.8.0') {
            exclude group: "com.android.support"
        }
        annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    

    查阅官方文档之后发现,4.x版本的Glide在接口调用和4.x之前有很大区别。

    在github的issue里,找到如下答案:

    To use the generated API in your application, you need to perform two steps:
    
    1.  Add a dependency on Glide’s annotation processor:
    
        ```
        repositories {
          mavenCentral()
        }
    
        dependencies {
          annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
        }
    
        ```
    
    2.  Include a [`AppGlideModule`]
    
        ```
        package com.example.myapp;
    
        import com.bumptech.glide.annotation.GlideModule;
        import com.bumptech.glide.module.AppGlideModule;
    
        @GlideModule
        public final class MyAppGlideModule extends AppGlideModule {}
    
        ```
    
    You’re not required to implement any of the methods in `AppGlideModule` for the
    API to be generated. You can leave the class blank as long as it 
    extends `AppGlideModule` and is annotated with `@GlideModule`.
    
    

    按照文档,添加AppGlideModule之后,问题解决。

    asBitmap() 接口找不到了

    查阅文档后发现是4.x的接口变动了

    for anyone came here and still have this issue, I found the way to fix it, 
    you must add the asBitmap() right After with() and it will work just like old times
    

    代码做如下修改后解决:

    // Put asBitmap() right after Glide.with(context)  for glide 4.x
            Glide.with(mActivity).asBitmap()
                    .load(url)
                    .listener(new RequestListener<Bitmap>() {
                                  @Override
                                  public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Bitmap> target, boolean b) {
                                      return false;
                                  }
    
                                  @Override
                                  public boolean onResourceReady(Bitmap bitmap, Object o, Target<Bitmap> target, DataSource dataSource, boolean b) {
                                      Log.d(TAG, "get serialNo : " + serialNo + " cover successful!");
                                      if (mPreviewingFaceMap.containsKey(serialNo)) {
                                          mPreviewingFaceMap.get(serialNo).activityCoverBitmap = bitmap;
                                      }
                                      return false;
                                  }
                              }
                    ).submit();
    

    上面两个问题,今天由于时间问题,没有进行深入了解,这里仅做解决方法的记录。
    后面我会对Glide4.0版本的接口修改以及官方文档提到的Generated API概念做深入的了解。

    相关文章

      网友评论

          本文标题:Glide升级到4.x版本遇到的问题

          本文链接:https://www.haomeiwen.com/subject/vtvqlqtx.html