{"record":{"id":"5fa37024b4d4c3e7","repo":"asLody/VirtualApp","slug":"unable-to-create-application-minitialapplication","errorCode":null,"errorMessage":"Unable to create application ${mInitialApplication.getClass().getName()}: ${e.toString()}","messagePattern":"Unable to create application (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/client/VClientImpl.java","lineNumber":342,"sourceCode":"        }\n        if (lock != null) {\n            lock.open();\n            mTempLock = null;\n        }\n        VirtualCore.get().getComponentDelegate().beforeApplicationCreate(mInitialApplication);\n        try {\n            mInstrumentation.callApplicationOnCreate(mInitialApplication);\n            InvocationStubManager.getInstance().checkEnv(HCallbackStub.class);\n            if (conflict) {\n                InvocationStubManager.getInstance().checkEnv(AppInstrumentation.class);\n            }\n            Application createdApp = ActivityThread.mInitialApplication.get(mainThread);\n            if (createdApp != null) {\n                mInitialApplication = createdApp;\n            }\n        } catch (Exception e) {\n            if (!mInstrumentation.onException(mInitialApplication, e)) {\n                throw new RuntimeException(\n                        \"Unable to create application \" + mInitialApplication.getClass().getName()\n                                + \": \" + e.toString(), e);\n            }\n        }\n        VActivityManager.get().appDoneExecuting();\n        VirtualCore.get().getComponentDelegate().afterApplicationCreate(mInitialApplication);\n    }\n\n    private void fixWeChatRecovery(Application app) {\n        try {\n            Field field = app.getClassLoader().loadClass(\"com.tencent.recovery.Recovery\").getField(\"context\");\n            field.setAccessible(true);\n            if (field.get(null) != null) {\n                return;\n            }\n            field.set(null, app.getBaseContext());\n        } catch (Throwable e) {\n            e.printStackTrace();","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/client/VClientImpl.java#L324-L360","documentation":"This RuntimeException is thrown by VClientImpl.bindApplicationNoCheck when the virtual (guest) app's Application class throws during its creation. The library creates the plugin app's Application instance via reflection/instrumentation, and if creation fails and the instrumentation does not handle the exception via onException, the error is rethrown wrapped in this message. The root cause is always in the plugin's Application subclass (or its onCreate/attachBaseContext).","triggerScenarios":"Calling bindApplication (directly or via the client process run loop) when the guest app's Application constructor, attach(), or onCreate() throws; mInstrumentation.onException returns false so the exception cannot be swallowed.","commonSituations":"Guest APK crashes during Application.onCreate (missing native libs, ContentProvider init failure, MultiDex errors on old devices); signature/permission checks inside the plugin's Application failing under virtualization; a plugin expecting an API not provided by the VA environment.","solutions":["Read the chained `caused by` exception — the RuntimeException is only a wrapper; fix the underlying crash in the plugin Application class","Run the plugin as a standalone app to confirm whether the crash is VA-specific or inherent to the plugin","Check that all plugin native libraries and assets are correctly extracted/loaded before application creation","Register a custom Instrumentation/handler or ComponentDelegate to intercept onException for graceful degradation"],"exampleFix":"// before\nApplication app = (Application) mActivityThread.mInstrumentation.newApplication(cl, appClass, appContext); // NPE inside plugin onCreate\n// after\ntry {\n    Application app = (Application) mInstrumentation.newApplication(cl, appClass, appContext);\n} catch (Throwable t) {\n    Log.e(TAG, \"plugin Application create failed\", t); // handle before VA wraps it\n}","handlingStrategy":"try-catch","validationCode":"// ensure plugin classes are loadable before bindApplication\ntry { Class.forName(appClassName, true, pluginClassLoader); } catch (ClassNotFoundException e) { /* abort launch */ }","typeGuard":"boolean isValidApplication(Object app) { return app instanceof Application && app.getClass().getName() != null; }","tryCatchPattern":"try { vClient.bindApplication(...) } catch (RuntimeException e) { Throwable root = e.getCause(); log(\"plugin app create failed\", root); }","preventionTips":["Test each plugin as a standalone app before virtualizing it","Keep plugin Application.onCreate lightweight and defensive","Log the chained cause exception, not just the wrapper message"],"tags":["android","virtualapp","application-creation","plugin-crash"],"backgroundTag":"internal-invariant-violation","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}