asLody/VirtualApp · error · java.lang.IllegalStateException

Must specify package name to remove a split

Error message

Must specify package name to remove a split

What it means

removeSplit() only makes sense for split-APK installs, which must be targeted at an explicit package name. If params.appPackageName is empty/null, the session has no package against which to mark a split for removal, so it throws IllegalStateException('Must specify package name to remove a split').

Solutions

  1. Set params.appPackageName (SessionParams.setAppPackageName) before creating the session.
  2. Only call removeSplit for sessions performing split-APK installs.
  3. If the package is unknown, skip removeSplit and instead install a fresh full APK replacing the old one.

Example fix

// before
SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL);
session.removeSplit("split_config.arm64_v8a"); // IllegalStateException

// after
SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName("com.example.app");
// ... create/open session ...
session.removeSplit("split_config.arm64_v8a");
Defensive patterns

Strategy: validation

Validate before calling

if (params == null || TextUtils.isEmpty(params.appPackageName)) {
    throw new IllegalArgumentException("appPackageName must be set before removeSplit");
}

Type guard

boolean canRemoveSplits(SessionParams p) { return p != null && !TextUtils.isEmpty(p.appPackageName); }

Try / catch

try {
    session.removeSplit(splitName);
} catch (IllegalStateException e) {
    if (String.valueOf(e.getMessage()).contains("Must specify package name")) {
        // re-create session with setAppPackageName, or skip split removal
    } else throw e;
}

Prevention

When it happens

Trigger: Calling session.removeSplit(splitName) on a session whose SessionParams.appPackageName was never set (e.g. install-mode params built without setting the package name).

Common situations: Installing via stream/data URL without an app package name; reusing generic SessionParams for a full APK install and then attempting split maintenance; VirtualApp flows where the base package was installed by other means.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at VirtualApp/lib/src/main/java/com/lody/virtual/server/pm/installer/PackageInstallerSession.java:353

        try {
            if (!FileUtils.isValidExtFilename(name)) {
                throw new IllegalArgumentException("Invalid name: " + name);
            }
            final File target = new File(resolveStageDir(), name);

            final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
            return ParcelFileDescriptor.dup(targetFd);

        } catch (ErrnoException e) {
            throw new IOException(e);
        }
    }

    @Override
    public void removeSplit(String splitName) throws RemoteException {
        if (TextUtils.isEmpty(params.appPackageName)) {
            throw new IllegalStateException("Must specify package name to remove a split");
        }
        try {
            createRemoveSplitMarker(splitName);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }

    private void createRemoveSplitMarker(String splitName) throws IOException {
        try {
            final String markerName = splitName + REMOVE_SPLIT_MARKER_EXTENSION;
            if (!FileUtils.isValidExtFilename(markerName)) {
                throw new IllegalArgumentException("Invalid marker: " + markerName);
            }
            final File target = new File(resolveStageDir(), markerName);
            target.createNewFile();
            Os.chmod(target.getAbsolutePath(), 0 /*mode*/);
        } catch (ErrnoException e) {

View on GitHub (pinned to 666fefcb5d)