alibaba/ARouter · error · HandlerException

Init provider failed! provider = [<name>], reason = [<failur

Error message

Init provider failed! provider = [<name>], reason = [<failure>]

What it means

completion() instantiates an IProvider for a route/provider meta, calls its init(context), and registers it in Warehouse. If construction, init, or registration throws, it logs 'Init provider failed!' and wraps the cause in HandlerException naming the provider class and failure reason.

Source

Thrown at arouter-api/src/main/java/com/alibaba/android/arouter/core/LogisticsCenter.java:345

                // Save raw uri
                postcard.withString(ARouter.RAW_URI, rawUri.toString());
            }

            switch (routeMeta.getType()) {
                case PROVIDER:  // if the route is provider, should find its instance
                    // Its provider, so it must implement IProvider
                    Class<? extends IProvider> providerMeta = (Class<? extends IProvider>) routeMeta.getDestination();
                    IProvider instance = Warehouse.providers.get(providerMeta);
                    if (null == instance) { // There's no instance of this provider
                        IProvider provider;
                        try {
                            provider = providerMeta.getConstructor().newInstance();
                            provider.init(mContext);
                            Warehouse.providers.put(providerMeta, provider);
                            instance = provider;
                        } catch (Exception e) {
                            logger.error(TAG, "Init provider failed!", e);
                            throw new HandlerException(
                                    "Init provider failed! provider = [" + providerMeta.getName()
                                            + "], reason = [" + describeFailure(e) + "]",
                                    e
                            );
                        }
                    }
                    postcard.setProvider(instance);
                    postcard.greenChannel();    // Provider should skip all of interceptors
                    break;
                case FRAGMENT:
                    postcard.greenChannel();    // Fragment needn't interceptors
                default:
                    break;
            }
        }
    }

    /**

View on GitHub (pinned to 84f451d244)

Solutions

  1. Read reason = [<failure>] and fix the exception thrown inside the provider's init()/constructor
  2. Ensure the provider class is public with a public no-arg constructor
  3. Guard provider init against missing configuration: validate required keys before init and fail early with a clear message
  4. Add keep rules so R8 doesn't break reflective instantiation: -keep class * implements com.alibaba.android.arouter.facade.template.IProvider { *; }

Example fix

// before
public class PayProvider implements IProvider {
    public PayProvider( Context c ) {...} // no default ctor
    @Override public void init(Context ctx) { key = Config.KEY; } // NPE if missing
}
// after
public class PayProvider implements IProvider {
    public PayProvider() {}
    @Override public void init(Context ctx) {
        String key = Config.get("pay.key");
        if (key == null || key.isEmpty()) {
            throw new IllegalStateException("pay.key not configured"); // surfaces clearly in reason
        }
        this.key = key;
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight provider requirements before triggering it via navigation
if (TextUtils.isEmpty(Config.get("pay.key"))) {
    Log.e(TAG, "pay.key missing; PayProvider init will fail");
}

Try / catch

try {
    IPayService pay = ARouter.getInstance().navigation(IPayService.class);
    pay.pay(order);
} catch (HandlerException e) {
    Log.e(TAG, "provider init failed: " + e.getMessage(), e.getCause());
    // degrade feature or surface config error
}

Prevention

When it happens

Trigger: Provider class has no public no-arg constructor (newInstance fails), its init() throws (e.g. missing API key, unmet service dependency), or Warehouse.providers registration fails; triggered on first navigation/service-fetch requiring that provider.

Common situations: Provider's init reads a missing config/env value; provider constructor does implicit dependency lookup that isn't ready; obfuscation renamed the class so reflective lookup breaks; provider incompatible with the current arouter-api version.

Related errors


AI-assisted analysis of alibaba/ARouter@84f451d244 (2026-09-06). Data as JSON: /api/errors/d71377dddeaddea1. Report an issue: GitHub.