{"record":{"id":"794c74627af8c081","repo":"bumptech/glide","slug":"glidemodule-can-only-be-applied-to-libraryglidemo","errorCode":null,"errorMessage":"@GlideModule can only be applied to LibraryGlideModule and AppGlideModule implementations, not: {}","messagePattern":"@GlideModule can only be applied to LibraryGlideModule and AppGlideModule implementations, not: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/LibraryModuleProcessor.java","lineNumber":32,"sourceCode":"  private final ProcessorUtil processorUtil;\n  private final IndexerGenerator indexerGenerator;\n\n  LibraryModuleProcessor(ProcessorUtil processorUtil, IndexerGenerator indexerGenerator) {\n    this.processorUtil = processorUtil;\n    this.indexerGenerator = indexerGenerator;\n  }\n\n  boolean processModules(RoundEnvironment env) {\n    // Order matters here, if we find an Indexer below, we return before writing the root module.\n    // If we fail to add to appModules before then, we might accidentally skip a valid RootModule.\n    List<TypeElement> libraryGlideModules = new ArrayList<>();\n    for (TypeElement element : processorUtil.getElementsFor(GlideModule.class, env)) {\n      // Root elements are added separately and must be checked separately because they're sub\n      // classes of LibraryGlideModules.\n      if (processorUtil.isAppGlideModule(element)) {\n        continue;\n      } else if (!processorUtil.isLibraryGlideModule(element)) {\n        throw new IllegalStateException(\n            \"@GlideModule can only be applied to LibraryGlideModule\"\n                + \" and AppGlideModule implementations, not: \"\n                + element);\n      }\n\n      libraryGlideModules.add(element);\n    }\n\n    processorUtil.debugLog(\"got child modules: \" + libraryGlideModules);\n    if (libraryGlideModules.isEmpty()) {\n      return false;\n    }\n\n    TypeSpec indexer = indexerGenerator.generate(libraryGlideModules);\n    processorUtil.writeIndexer(indexer);\n    processorUtil.debugLog(\n        \"Wrote an Indexer this round, skipping the app module to ensure all \"\n            + \"indexers are found\");","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/LibraryModuleProcessor.java#L14-L50","documentation":"@GlideModule is only valid on classes that extend LibraryGlideModule (for libraries) or AppGlideModule (for applications). LibraryModuleProcessor.processModules iterates @GlideModule-annotated elements; after skipping AppGlideModules, any remaining class that is not a LibraryGlideModule is rejected with the offending class name.","triggerScenarios":"LibraryModuleProcessor.processModules: `if (isAppGlideModule) continue; else if (!isLibraryGlideModule) throw`. Hit by annotating a plain class, an interface, an abstract class, or any class that does not extend com.bumptech.glide.module.LibraryGlideModule with @GlideModule.","commonSituations":"Adding @GlideModule to a class extending AppGlideModule's sibling without the right base class; annotating a Kotlin `object` or interface; annotating a custom class hoping Glide will treat it as a module; copy-paste from an AppGlideModule into a class that should be a LibraryGlideModule but missing the `extends LibraryGlideModule`.","solutions":["If the class is for an application, have it extend com.bumptech.glide.module.AppGlideModule (only one allowed per app).","If it is for a library, have it extend com.bumptech.glide.module.LibraryGlideModule and implement registerComponents(...).","If the class is neither, remove the @GlideModule annotation entirely."],"exampleFix":"// before\n@GlideModule\npublic class MyOkHttpModule {\n  public void registerComponents(Context ctx, Glide glide, Registry registry) { ... }\n}\n\n// after\n@GlideModule\npublic class MyOkHttpModule extends LibraryGlideModule {\n  @Override\n  public void registerComponents(@NonNull Context ctx, @NonNull Glide glide, @NonNull Registry registry) { ... }\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Let the compiler enforce the base class at declaration time.\n@GlideModule\npublic class MyLibraryModule extends com.bumptech.glide.module.LibraryGlideModule {\n  @Override\n  public void registerComponents(@NonNull android.content.Context context,\n                                 @NonNull com.bumptech.glide.Glide glide,\n                                 @NonNull com.bumptech.glide.Registry registry) {\n    // ...\n  }\n}\n// For applications, use: extends com.bumptech.glide.module.AppGlideModule (max one per app).","tryCatchPattern":null,"preventionTips":["@GlideModule only goes on classes extending LibraryGlideModule or AppGlideModule.","Never put @GlideModule on interfaces, abstract classes, or plain POJOs.","When converting a sample, always add the correct `extends` clause."],"tags":["glide","annotation-processing","glidemodule","inheritance"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}