alibaba/ARouter · critical · InitException
ARouterCore::Init::Invoke init(context) first!
Error message
ARouterCore::Init::Invoke init(context) first!
What it means
_ARouter.getInstance() is the internal core accessor and throws InitException when hasInit is false. The core is only usable after ARouter.init(context) populated the generated route metadata; failing fast prevents navigation against an empty route map.
Source
Thrown at arouter-api/src/main/java/com/alibaba/android/arouter/launcher/_ARouter.java:88
return true;
}
/**
* Destroy arouter, it can be used only in debug mode.
*/
static synchronized void destroy() {
if (debuggable()) {
hasInit = false;
LogisticsCenter.suspend();
logger.info(Consts.TAG, "ARouter destroy success!");
} else {
logger.error(Consts.TAG, "Destroy can be used in debug mode only!");
}
}
protected static _ARouter getInstance() {
if (!hasInit) {
throw new InitException("ARouterCore::Init::Invoke init(context) first!");
} else {
if (instance == null) {
synchronized (_ARouter.class) {
if (instance == null) {
instance = new _ARouter();
}
}
}
return instance;
}
}
static synchronized void openDebug() {
debuggable = true;
logger.info(Consts.TAG, "ARouter openDebug");
}
static synchronized void openLog() {View on GitHub (pinned to 84f451d244)
Solutions
- Initialize ARouter in Application.onCreate() before anything else uses routing
- If init fails, verify annotation processors (arouter-compiler) ran and the module's generated classes are packaged (clean build)
- For instrumented/unit tests, initialize with the test Application context before calling routing APIs
Example fix
// before
protected void onCreate(Bundle b) {
ARouter.getInstance().build("/user/login").navigation(); // reaches _ARouter, throws
// after
@Override protected void onCreate(Bundle b) {
if (!ARouter.debuggable()) { /* init already done in Application */ }
ARouter.getInstance().build("/user/login").navigation(); Defensive patterns
Strategy: validation
Validate before calling
if (application == null || !isMainProcessReady()) {
return; // skip routing until init completed
} Try / catch
try {
ARouter.getInstance().inject(this);
} catch (InitException e) {
Log.e(TAG, "Router core not initialized", e);
} Prevention
- Single init point in Application.onCreate
- Avoid routing calls in tests without an initialized Application
- Keep arouter-api and compiler plugin versions in sync so init succeeds
When it happens
Trigger: Any API that internally reaches _ARouter.getInstance() (build, navigation, inject, hasRoute) executed before ARouter.init(context) finished, or after init failed.
Common situations: Same root cause as the public ARouter init error: missing init in Application, init failure due to missing ARouter$$Root/ARouter$$Providers generated classes, or unit tests invoking routing APIs without a fake init.
Related errors
- ARouter::Init::Invoke init(context) first!
- The field '<fieldName>' is null, in class '<className>!
- Parameter is invalid!
- Parameter invalid!
- Extract the default group failed, the path must be start wit
AI-assisted analysis of alibaba/ARouter@84f451d244 (2026-09-06).
Data as JSON: /api/errors/c342c10f83f01ee9.
Report an issue: GitHub.