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();
 
原文地址:https://www.cnblogs.com/yelanggu/p/10831516.html