Tencent/tinker · critical · IllegalStateException

TinkerApplication is not initialized.

Error message

TinkerApplication is not initialized.

What it means

TinkerApplication.getInstance() returns the process-wide singleton stored in SELF_HOLDER, which is set in the TinkerApplication constructor. If the application class has not yet been constructed, the holder slot is null and getInstance throws IllegalStateException. This almost always means the caller invoked Tinker.with()/getInstance() before Application creation or in a context where the custom TinkerApplication is not the manifest application.

Source

Thrown at tinker-android/tinker-android-loader-no-op/src/main/java/com/tencent/tinker/loader/app/TinkerApplication.java:80

    }

    protected TinkerApplication(int tinkerFlags, String delegateClassName,
                                String loaderClassName, boolean tinkerLoadVerifyFlag,
                                boolean useDelegateLastClassLoader, boolean useInterpretModeOnSupported32BitSystem) {
        synchronized (SELF_HOLDER) {
            SELF_HOLDER[0] = this;
        }
        this.tinkerFlags = ShareConstants.TINKER_DISABLE;
        this.delegateClassName = delegateClassName;
        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;
        this.useDelegateLastClassLoader = useDelegateLastClassLoader;
        this.useInterpretModeOnSupported32BitSystem = useInterpretModeOnSupported32BitSystem;
    }

    public static TinkerApplication getInstance() {
        synchronized (SELF_HOLDER) {
            if (SELF_HOLDER[0] == null) {
                throw new IllegalStateException("TinkerApplication is not initialized.");
            }
            return SELF_HOLDER[0];
        }
    }

    private ApplicationLike createDelegate(Application app,
                                           int tinkerFlags,
                                           String delegateClassName,
                                           boolean tinkerLoadVerifyFlag,
                                           long applicationStartElapsedTime,
                                           long applicationStartMillisTime,
                                           Intent resultIntent) {
        try {
            // Use reflection to create the delegate so it doesn't need to go into the primary dex.
            // And we can also patch it
            final Class<?> delegateClass = Class.forName(delegateClassName, false, mCurrentClassLoader);
            final Constructor<?> constructor = delegateClass.getConstructor(Application.class, int.class, boolean.class,
                    long.class, long.class, Intent.class);

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Ensure the manifest android:name points to your TinkerApplication subclass (or the generated DefaultTinkerApplication).
  2. Move Tinker.with()/TinkerInstaller calls into Application.onCreate()/onBaseContextAttached() or later in the lifecycle, never into static blocks or ContentProviders that initialize first.
  3. Delay provider initialization (setProviderEnabled(false) on lazy providers, or init them in Application.onCreate()).
  4. In tests, construct or mock the Application before hitting Tinker APIs.

Example fix

// before (crashes in a ContentProvider that starts before the app)
public boolean onCreate() {
    Tinker.with(getContext()).install(loadReporter); // IllegalStateException
    return true;
}

// after (defer to Application)
public class MyApplication extends TinkerApplication {
    @Override public void onCreate() {
        super.onCreate();
        Tinker.install(this); // safe: application constructed
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// guard any early Tinker access (e.g. in providers)
private static boolean tinkerReady() {
    try {
        TinkerApplication.getInstance();
        return true;
    } catch (IllegalStateException e) {
        return false;
    }
}

Try / catch

try {
    Tinker.with(context).install(reporter);
} catch (IllegalStateException e) {
    // Application not constructed yet: defer init to Application.onCreate()
}

Prevention

When it happens

Trigger: Calling TinkerApplication.getInstance() (directly or via Tinker.with(context)) before the TinkerApplication subclass instance was constructed — e.g. from a static initializer, ContentProvider.onCreate() that runs before Application, or from code running in a process whose manifest application is not the TinkerApplication.

Common situations: Using a ContentProvider or backup agent that initializes before the Application; manifest not declaring the generated TinkerApplication subclass (or DefaultTinkerApplication); proguard stripping/renaming the application class; calling Tinker APIs from instrumented tests where the real Application never runs.

Related errors


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