找不到GeneratedAppGlideModule错误

时间:2019-06-19 18:36:10

标签: android android-glide

我以前使用Glide库在android中加载图像Glide可以轻松加载图像,但现在它显示错误,尽管图像URL显示在日志目录中,但无法加载到图像视图中。

它显示以下错误:

  

无法找到GeneratedAppGlideModule。您应该包括一个       commentProcessor的编译依赖       com.github.bumptech.glide:您的应用程序中的编译器和       @GlideModule注释的AppGlideModule实现或       LibraryGlideModules将被静默忽略

build.gradle

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
    maven { url 'https://maven.google.com' }
}

android {
     compileSdkVersion 28
defaultConfig {
    applicationId "com.app.bookbudiapp"
    minSdkVersion 16
    targetSdkVersion 28
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {

     implementation 'com.github.bumptech.glide:glide:4.8.0'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}  

apply plugin: 'com.google.gms.google-services'

MyGlideApp

@GlideModule
public class MyGlideApp extends AppGlideModule {}

HomeOfferAdapter.java

     public class HomeOfferAdapter extends PagerAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<HomeOffersModel> banners;

    public HomeOfferAdapter(List<HomeOffersModel> banners,Context context){

                 this.banners = banners;
                 this.context = context;
    }

    @Override
    public int getCount() {
        return banners.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {

        layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        assert layoutInflater != null;
        View view = layoutInflater.inflate(R.layout.onboard_frag,container,false);

        ImageView slideImage = view.findViewById(R.id.offerImage);

        HomeOffersModel model = banners.get(position);

      //  RequestOptions options = new RequestOptions();
      //  options.placeholder(R.drawable.openbook);



            GlideApp.with(context).load(model.getOffers()).placeholder(R.drawable.openbook).into(slideImage);


        container.addView(view);

        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((LinearLayout)object);
    }
}

重建项目后出现错误:

Caused by: java.lang.NullPointerException
at com.bumptech.glide.annotation.compiler.ProcessorUtil.findInstanceMethodsReturning(ProcessorUtil.java:474)
at com.bumptech.glide.annotation.compiler.RequestOptionsOverrideGenerator.generateInstanceMethodOverridesForRequestOptions(RequestOptionsOverrideGenerator.java:49)
at com.bumptech.glide.annotation.compiler.RequestOptionsOverrideGenerator.generateInstanceMethodOverridesForRequestOptions(RequestOptionsOverrideGenerator.java:41)
at com.bumptech.glide.annotation.compiler.RequestOptionsGenerator.generate(RequestOptionsGenerator.java:157)
at com.bumptech.glide.annotation.compiler.AppModuleProcessor.maybeWriteAppModule(AppModuleProcessor.java:87)
at com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor.process(GlideAnnotationProcessor.java:131)
at org.gradle.api.internal.tasks.compile.processing.DelegatingProcessor.process(DelegatingProcessor.java:62)
at org.gradle.api.internal.tasks.compile.processing.AggregatingProcessor.process(AggregatingProcessor.java:50)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
... 69 more

请让我知道我做错了什么。任何帮助将不胜感激。

谢谢

2 个答案:

答案 0 :(得分:1)

根据Glide在GitHub上的文档:

repositories {
  mavenCentral()
  google() // You were missing this
}

 dependencies {
  implementation 'com.github.bumptech.glide:glide:4.9.0' //bumped from 4.8.0 to 4.9.0
  annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
}

始终确保使用最新版本。这是由于项目级gradle文件中缺少google()存储库引起的。

答案 1 :(得分:0)

尝试重建项目并使用GlideApp代替Glide,如以下代码所示:

GlideApp.with(context).load(model.getOffers).apply(options).into(slideImage);