Tencent/tinker · error · IllegalStateException

failed to fetch instance of ActivityThread.

Error message

failed to fetch instance of ActivityThread.

What it means

ComponentHotplug (incremental activity/service hot-plugging) hooks ActivityThread.mH to intercept component lifecycle messages. fetchMHInstance calls ShareReflectUtil.getActivityThread(context, null) and throws this IllegalStateException when it cannot obtain the ActivityThread instance, meaning the component-hotplug interceptor cannot be installed.

Source

Thrown at tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/hotplug/ComponentHotplug.java:86

                sPMSInterceptor.install();
                if (Build.VERSION.SDK_INT < 27) {
                    sMHMessageInterceptor.install();
                } else {
                    sTinkerHackInstrumentation.install();
                }
            } catch (Throwable thr) {
                uninstall();
                throw new UnsupportedEnvironmentException(thr);
            }
        } else {
            ShareTinkerLog.i(TAG, "method install() is not invoked, ignore ensuring operations.");
        }
    }

    private static Handler fetchMHInstance(Context context) {
        final Object activityThread = ShareReflectUtil.getActivityThread(context, null);
        if (activityThread == null) {
            throw new IllegalStateException("failed to fetch instance of ActivityThread.");
        }
        try {
            final Field mHField = ShareReflectUtil.findField(activityThread, "mH");
            final Handler mH = (Handler) mHField.get(activityThread);
            return mH;
        } catch (Throwable thr) {
            throw new IllegalStateException(thr);
        }
    }

    public synchronized static void uninstall()  {
        if (sInstalled) {
            try {
                sAMSInterceptor.uninstall();
                sPMSInterceptor.uninstall();
                if (Build.VERSION.SDK_INT < 27) {
                    sMHMessageInterceptor.uninstall();
                } else {

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Update Tinker to a release supporting the device's API level.
  2. If using ComponentHotplug, guard it with try-catch for UnsupportedEnvironmentException/IllegalStateException and degrade to non-hotplug mode (components declared in the base manifest).
  3. Avoid enabling incremental-component hotplug on the affected ROM via server-side config.
Defensive patterns

Strategy: try-catch

Validate before calling

try {
    Object at = ShareReflectUtil.getActivityThread(context, null);
    if (at == null) return; // hotplug unsupported here
    ShareReflectUtil.findField(at, "mH");
} catch (Throwable t) {
    // environment unsupported: skip component hotplug
}

Try / catch

try {
    ComponentHotplug.install(context);
} catch (UnsupportedEnvironmentException | IllegalStateException e) {
    // ActivityThread internals unavailable: degrade to base-manifest components
}

Prevention

When it happens

Trigger: Reflection into android.app.ActivityThread (currentActivityThread field or static ActivityThread field) returning null on ROMs where it is renamed, blocked by hidden-API restrictions, or where the class was shaded/repackaged by the OEM.

Common situations: Android P+ hidden API greylisting; OEM frameworks; test environments (Robolectric) lacking a real ActivityThread.

Related errors


AI-assisted analysis of Tencent/tinker@1b7ea02c23 (2026-08-14). Data as JSON: /api/errors/86e50342574125ef. Report an issue: GitHub.