{"record":{"id":"b3c739347bc041ae","repo":"Tencent/tinker","slug":"you-must-install-tinker-before-get-tinker-sinstanc-b3c739","errorCode":null,"errorMessage":"you must install tinker before get tinker sInstance","messagePattern":"you must install tinker before get tinker sInstance","errorType":"exception","errorClass":"TinkerRuntimeException","httpStatus":null,"severity":"error","filePath":"tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java","lineNumber":107,"sourceCode":"        this.patchDirectory = patchDirectory;\n        this.patchInfoFile = patchInfoFile;\n        this.patchInfoLockFile = patchInfoLockFile;\n        this.customPatcher = customPatcher;\n        this.isMainProcess = isInMainProc;\n        this.tinkerLoadVerifyFlag = tinkerLoadVerifyFlag;\n        this.isPatchProcess = isPatchProcess;\n    }\n\n    /**\n     * init with default config tinker\n     * for safer, you must use @{link TinkerInstaller.install} first!\n     *\n     * @param context we will use the application context\n     * @return the Tinker object\n     */\n    public static Tinker with(Context context) {\n        if (!sInstalled) {\n            throw new TinkerRuntimeException(\"you must install tinker before get tinker sInstance\");\n        }\n        synchronized (Tinker.class) {\n            if (sInstance == null) {\n                sInstance = new Builder(context).build();\n            }\n        }\n        return sInstance;\n    }\n\n    /**\n     * create custom tinker by {@link Tinker.Builder}\n     * please do it when very first your app start.\n     *\n     * @param tinker\n     */\n    public static void create(Tinker tinker) {\n        if (sInstance != null) {\n            throw new TinkerRuntimeException(\"Tinker instance is already set.\");","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-android/tinker-android-lib/src/main/java/com/tencent/tinker/lib/tinker/Tinker.java#L89-L125","documentation":"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.","triggerScenarios":"Any call to Tinker.with(context) (directly or via helper APIs like TinkerInstaller.onReceiveUpgradePatch) before Tinker.install(...) executed in the current process.","commonSituations":"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.","solutions":["Call TinkerInstaller.install (or Tinker.install) in DefaultApplicationLike.onCreate / onBaseContextAttached before any other tinker API use.","Gate API usage with Tinker.isTinkerInstalled() before calling Tinker.with(...).","For components in secondary processes, ensure the Application (and thus install) runs there before dispatching patch work to them."],"exampleFix":"// before\npublic void onReceiveUpgradePatch(String path) {\n    Tinker.with(context).getPatchListener();\n}\n\n// after\nif (Tinker.isTinkerInstalled()) {\n    Tinker.with(context).getPatchListener();\n}","handlingStrategy":"validation","validationCode":"if (Tinker.isTinkerInstalled()) {\n    Tinker tinker = Tinker.with(context);\n    // safe to use APIs\n} else {\n    deferUntilInstalled();\n}","typeGuard":"public static Tinker tinkerOrNull(Context ctx) {\n    return Tinker.isTinkerInstalled() ? Tinker.with(ctx) : null;\n}","tryCatchPattern":null,"preventionTips":["Call TinkerInstaller.install first in ApplicationLike before any Tinker.with usage.","Wrap third-party code that may call Tinker.with with an isTinkerInstalled() check.","Initialize tinker in onBaseContextAttached/onCreate, before spawning threads that use it."],"tags":["tinker","android","initialization","ordering","null-check"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}