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


     

    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();
    
     
  • 相关阅读:
    个人作业——软件工程实践总结作业
    团队作业第二次—项目选题报告
    结对第二次—文献摘要热词统计及进阶需求
    结对第一次—原型设计(文献摘要热词统计)
    第一次作业-准备篇
    Java面向对象课程设计——购物车
    第04次作业-树
    第03次作业-栈和队列
    第02次作业-线性表
    01——绪论作业
  • 原文地址:https://www.cnblogs.com/yelanggu/p/10831516.html
Copyright © 2020-2023  润新知