asLody/VirtualApp · error · RuntimeException

Unable to create application

Error message

Unable to create application ${mInitialApplication.getClass().getName()}: ${e.toString()}

What it means

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).

Solutions

  1. Read the chained `caused by` exception — the RuntimeException is only a wrapper; fix the underlying crash in the plugin Application class
  2. Run the plugin as a standalone app to confirm whether the crash is VA-specific or inherent to the plugin
  3. Check that all plugin native libraries and assets are correctly extracted/loaded before application creation
  4. Register a custom Instrumentation/handler or ComponentDelegate to intercept onException for graceful degradation

Example fix

// before
Application app = (Application) mActivityThread.mInstrumentation.newApplication(cl, appClass, appContext); // NPE inside plugin onCreate
// after
try {
    Application app = (Application) mInstrumentation.newApplication(cl, appClass, appContext);
} catch (Throwable t) {
    Log.e(TAG, "plugin Application create failed", t); // handle before VA wraps it
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure plugin classes are loadable before bindApplication
try { Class.forName(appClassName, true, pluginClassLoader); } catch (ClassNotFoundException e) { /* abort launch */ }

Type guard

boolean isValidApplication(Object app) { return app instanceof Application && app.getClass().getName() != null; }

Try / catch

try { vClient.bindApplication(...) } catch (RuntimeException e) { Throwable root = e.getCause(); log("plugin app create failed", root); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of asLody/VirtualApp@666fefcb5d (2026-09-09). Data as JSON: /api/errors/5fa37024b4d4c3e7. Report an issue: GitHub.

Appendix: source

Thrown at VirtualApp/lib/src/main/java/com/lody/virtual/client/VClientImpl.java:342

        }
        if (lock != null) {
            lock.open();
            mTempLock = null;
        }
        VirtualCore.get().getComponentDelegate().beforeApplicationCreate(mInitialApplication);
        try {
            mInstrumentation.callApplicationOnCreate(mInitialApplication);
            InvocationStubManager.getInstance().checkEnv(HCallbackStub.class);
            if (conflict) {
                InvocationStubManager.getInstance().checkEnv(AppInstrumentation.class);
            }
            Application createdApp = ActivityThread.mInitialApplication.get(mainThread);
            if (createdApp != null) {
                mInitialApplication = createdApp;
            }
        } catch (Exception e) {
            if (!mInstrumentation.onException(mInitialApplication, e)) {
                throw new RuntimeException(
                        "Unable to create application " + mInitialApplication.getClass().getName()
                                + ": " + e.toString(), e);
            }
        }
        VActivityManager.get().appDoneExecuting();
        VirtualCore.get().getComponentDelegate().afterApplicationCreate(mInitialApplication);
    }

    private void fixWeChatRecovery(Application app) {
        try {
            Field field = app.getClassLoader().loadClass("com.tencent.recovery.Recovery").getField("context");
            field.setAccessible(true);
            if (field.get(null) != null) {
                return;
            }
            field.set(null, app.getBaseContext());
        } catch (Throwable e) {
            e.printStackTrace();

View on GitHub (pinned to 666fefcb5d)