MuntashirAkon/AppManager · error · JSONException

Package name is missing.

Error message

Package name is missing.

What it means

ApkQueueItem.validateForReplay re-validates a deserialized install-queue item before generating its executable intent. If the item represents an 'install existing package' action (mInstallExisting) but no package name was stored, it throws JSONException because the replay intent cannot target any package.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/installer/ApkQueueItem.java:231

        mOperationId = !TextUtils.isEmpty(operationId) ? operationId : UUID.randomUUID().toString();
        mPackageName = JSONUtils.optString(jsonObject, "package_name", null);
        mAppLabel = JSONUtils.optString(jsonObject, "app_label", null);
        mInstallExisting = jsonObject.optBoolean("install_existing", false);
        mTestOnly = jsonObject.optBoolean("test_only", false);
        mOriginatingPackage = JSONUtils.optString(jsonObject, "originating_package", null);
        String originatingUri = JSONUtils.optString(jsonObject, "originating_uri", null);
        mOriginatingUri = originatingUri != null ? Uri.parse(originatingUri) : null;
        JSONObject apkSource = jsonObject.optJSONObject("apk_source");
        mApkSource = apkSource != null ? ApkSource.DESERIALIZER.deserialize(apkSource) : null;
        JSONObject installerOptions = jsonObject.optJSONObject("installer_options");
        mInstallerOptions = installerOptions != null ? InstallerOptions.DESERIALIZER.deserialize(installerOptions) : null;
        mSelectedSplits = JSONUtils.getArray(jsonObject.optJSONArray("selected_splits"));
    }

    public void validateForReplay() throws JSONException {
        if (mInstallExisting) {
            if (TextUtils.isEmpty(mPackageName)) {
                throw new JSONException("Package name is missing.");
            }
        } else {
            if (mApkSource == null) {
                throw new JSONException("APK source is missing.");
            }
            if (mSelectedSplits == null || mSelectedSplits.isEmpty()) {
                throw new JSONException("Selected APK splits are missing.");
            }
        }
        if (mInstallerOptions != null) {
            setInstallerOptions(InstallerOptions.resolveEffectiveOptions(mInstallerOptions,
                    mPackageName, mTestOnly));
        }
    }

    @NonNull
    @Override
    public JSONObject serializeToJson() throws JSONException {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Ensure the JSON record contains a non-empty "package_name" whenever "install_existing" is true.
  2. Validate the queue JSON schema before deserializing (check optJSONObject/has on required keys).
  3. Wrap validateForReplay/getExecutableIntent in try-catch for JSONException and skip/requeue invalid items.
  4. Migrate old queue entries: if install_existing is set and package_name is blank, prompt the user to re-select the package or drop the item.

Example fix

// before
item.validateForReplay();
Intent intent = item.getExecutableIntent();
// after
try {
    item.validateForReplay();
    Intent intent = item.getExecutableIntent();
} catch (JSONException e) {
    queue.remove(item); // drop malformed replay entry
}
Defensive patterns

Strategy: validation

Validate before calling

if (json.optBoolean("install_existing") && TextUtils.isEmpty(json.optString("package_name"))) {
    throw new JSONException("install_existing requires package_name");
}

Try / catch

try {
    item.validateForReplay();
} catch (JSONException e) {
    Log.w(TAG, "Skipping invalid queue item: " + e.getMessage());
}

Prevention

When it happens

Trigger: Replaying a queued install created from JSON where the "install_existing" flag is true but the "package_name" field is missing, null, or empty (TextUtils.isEmpty) — typically after hand-editing the queue file or an older schema version writing incomplete records.

Common situations: Restoring sessions from backup/restore of the app's install queue, importing queue JSON shared between devices with schema drift, or corrupt/partially written queue entries.

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 MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/bac9050de610ea64. Report an issue: GitHub.