Tencent/QMUI_Android · error · IllegalStateException

customFactory must implement interface QMUISchemeIntentFacto

Error message

customFactory must implement interface QMUISchemeIntentFactory.

What it means

SchemeProcessor.generateCustomFactory validates the customFactory annotation value at compile time. For @SchemeActivity (isActivity == true) the provided class must implement QMUISchemeIntentFactory; otherwise the processor throws this IllegalStateException, failing the build.

Source

Thrown at arch-compiler/src/main/java/com/qmuiteam/qmui/arch/SchemeProcessor.java:343

                    builder.add(",");
                }
                builder.add("$S", keys[i]);
            }
            builder.add("}");
        }
        return builder.build();
    }


    private CodeBlock generateCustomFactory(boolean isActivity, AnnotationMirror annotationMirror){
        AnnotationValue customFactory = getAnnotationValue(annotationMirror, "customFactory");
        if (customFactory == null) {
            return CodeBlock.of("null");
        }
        TypeMirror typeMirror = (TypeMirror) customFactory.getValue();
        if(isActivity){
            if (!isSubtypeOfType(typeMirror, QMUISchemeIntentFactoryType)) {
                throw new IllegalStateException("customFactory must implement interface QMUISchemeIntentFactory.");
            }
        }else{
            if (!isSubtypeOfType(typeMirror, QMUISchemeFragmentFactoryType)) {
                throw new IllegalStateException("customFactory must implement interface QMUISchemeFragmentFactory.");
            }
        }

        return CodeBlock.of("$T.class", typeMirror);
    }

    private CodeBlock generateCustomMatcher(AnnotationMirror annotationMirror){
        AnnotationValue customFactory = getAnnotationValue(annotationMirror, "customMatcher");
        if (customFactory == null) {
            return CodeBlock.of("null");
        }
        TypeMirror typeMirror = (TypeMirror) customFactory.getValue();
        if (!isSubtypeOfType(typeMirror, QMUISchemeMatcherType)) {
            throw new IllegalStateException("customMatcher must implement interface QMUISchemeMatcher.");

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Make the customFactory class implement QMUISchemeIntentFactory for activity schemes.
  2. Verify you imported the correct QMUISchemeIntentFactory interface (arch scheme package).
  3. If the class was meant for a fragment, switch the annotation/site to use QMUISchemeFragmentFactory instead.

Example fix

// before
class MyFactory { override fun ... } // no interface

// after
class MyFactory : QMUISchemeIntentFactory { override fun create(context: Context, ...): Intent? = ... }
Defensive patterns

Strategy: validation

Validate before calling

// at the declaration site, ensure:
// class MyFactory : QMUISchemeIntentFactory  <-- required for activity schemes
fun validateActivityFactory(cls: Class<*>) =
    check(QMUISchemeIntentFactory::class.java.isAssignableFrom(cls)) { "${cls.name} must implement QMUISchemeIntentFactory" }

Type guard

fun isValidActivityFactory(cls: Class<*>): Boolean =
    QMUISchemeIntentFactory::class.java.isAssignableFrom(cls)

Prevention

When it happens

Trigger: Annotating an Activity with a scheme annotation whose customFactory element points to a class that does not implement QMUISchemeIntentFactory.

Common situations: Copy-pasting a fragment factory into an activity scheme; refactoring the factory to drop the interface; typos in the import causing the wrong QMUISchemeIntentFactory to be referenced.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/2c8b415861faf61b. Report an issue: GitHub.