Tencent/tinker · error · TinkerRuntimeException

you must install tinker before get tinker sInstance

Error message

you must install tinker before get tinker sInstance

What it means

Tinker.with(context) is the static accessor for the singleton, but it refuses to run before Tinker.install(...) has set sInstalled. Throwing here is tinker's guard against using any Tinker API before initialization. The comment on the method states you must use TinkerInstaller.install first.

Source

Thrown at tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java:107

        this.patchDirectory = patchDirectory;
        this.patchInfoFile = patchInfoFile;
        this.patchInfoLockFile = patchInfoLockFile;
        this.customPatcher = customPatcher;
        this.isMainProcess = isInMainProc;
        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;
        this.isPatchProcess = isPatchProcess;
    }

    /**
     * init with default config tinker
     * for safer, you must use @{link TinkerInstaller.install} first!
     *
     * @param context we will use the application context
     * @return the Tinker object
     */
    public static Tinker with(Context context) {
        if (!sInstalled) {
            throw new TinkerRuntimeException("you must install tinker before get tinker sInstance");
        }
        synchronized (Tinker.class) {
            if (sInstance == null) {
                sInstance = new Builder(context).build();
            }
        }
        return sInstance;
    }

    /**
     * create custom tinker by {@link Tinker.Builder}
     * please do it when very first your app start.
     *
     * @param tinker
     */
    public static void create(Tinker tinker) {
        if (sInstance != null) {
            throw new TinkerRuntimeException("Tinker instance is already set.");

View on GitHub (pinned to 1b7ea02c23)

Solutions

  1. Call TinkerInstaller.install (or Tinker.install) in DefaultApplicationLike.onCreate / onBaseContextAttached before any other tinker API use.
  2. Gate API usage with Tinker.isTinkerInstalled() before calling Tinker.with(...).
  3. For components in secondary processes, ensure the Application (and thus install) runs there before dispatching patch work to them.

Example fix

// before
public void onReceiveUpgradePatch(String path) {
    Tinker.with(context).getPatchListener();
}

// after
if (Tinker.isTinkerInstalled()) {
    Tinker.with(context).getPatchListener();
}
Defensive patterns

Strategy: validation

Validate before calling

if (Tinker.isTinkerInstalled()) {
    Tinker tinker = Tinker.with(context);
    // safe to use APIs
} else {
    deferUntilInstalled();
}

Type guard

public static Tinker tinkerOrNull(Context ctx) {
    return Tinker.isTinkerInstalled() ? Tinker.with(ctx) : null;
}

Prevention

When it happens

Trigger: Any call to Tinker.with(context) (directly or via helper APIs like TinkerInstaller.onReceiveUpgradePatch) before Tinker.install(...) executed in the current process.

Common situations: Calling tinker APIs from a background thread or another process (content provider, broadcast receiver) that races ahead of Application.onCreate's install; app code running in onCreate before the DefaultApplicationLike's onBaseContextAttached completes install; forgetting TinkerInstaller.install entirely in a demo/smoke build.

Related errors


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