bumptech/glide · error · IllegalStateException

@GlideModule can only be applied to LibraryGlideModule and A

Error message

@GlideModule can only be applied to LibraryGlideModule and AppGlideModule implementations, not: {}

What it means

@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.

Source

Thrown at annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/LibraryModuleProcessor.java:32

  private final ProcessorUtil processorUtil;
  private final IndexerGenerator indexerGenerator;

  LibraryModuleProcessor(ProcessorUtil processorUtil, IndexerGenerator indexerGenerator) {
    this.processorUtil = processorUtil;
    this.indexerGenerator = indexerGenerator;
  }

  boolean processModules(RoundEnvironment env) {
    // Order matters here, if we find an Indexer below, we return before writing the root module.
    // If we fail to add to appModules before then, we might accidentally skip a valid RootModule.
    List<TypeElement> libraryGlideModules = new ArrayList<>();
    for (TypeElement element : processorUtil.getElementsFor(GlideModule.class, env)) {
      // Root elements are added separately and must be checked separately because they're sub
      // classes of LibraryGlideModules.
      if (processorUtil.isAppGlideModule(element)) {
        continue;
      } else if (!processorUtil.isLibraryGlideModule(element)) {
        throw new IllegalStateException(
            "@GlideModule can only be applied to LibraryGlideModule"
                + " and AppGlideModule implementations, not: "
                + element);
      }

      libraryGlideModules.add(element);
    }

    processorUtil.debugLog("got child modules: " + libraryGlideModules);
    if (libraryGlideModules.isEmpty()) {
      return false;
    }

    TypeSpec indexer = indexerGenerator.generate(libraryGlideModules);
    processorUtil.writeIndexer(indexer);
    processorUtil.debugLog(
        "Wrote an Indexer this round, skipping the app module to ensure all "
            + "indexers are found");

View on GitHub (pinned to eb14a895d8)

Solutions

  1. If the class is for an application, have it extend com.bumptech.glide.module.AppGlideModule (only one allowed per app).
  2. If it is for a library, have it extend com.bumptech.glide.module.LibraryGlideModule and implement registerComponents(...).
  3. If the class is neither, remove the @GlideModule annotation entirely.

Example fix

// before
@GlideModule
public class MyOkHttpModule {
  public void registerComponents(Context ctx, Glide glide, Registry registry) { ... }
}

// after
@GlideModule
public class MyOkHttpModule extends LibraryGlideModule {
  @Override
  public void registerComponents(@NonNull Context ctx, @NonNull Glide glide, @NonNull Registry registry) { ... }
}
Defensive patterns

Strategy: type-guard

Type guard

// Let the compiler enforce the base class at declaration time.
@GlideModule
public class MyLibraryModule extends com.bumptech.glide.module.LibraryGlideModule {
  @Override
  public void registerComponents(@NonNull android.content.Context context,
                                 @NonNull com.bumptech.glide.Glide glide,
                                 @NonNull com.bumptech.glide.Registry registry) {
    // ...
  }
}
// For applications, use: extends com.bumptech.glide.module.AppGlideModule (max one per app).

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/794c74627af8c081. Report an issue: GitHub.