bazelbuild/bazel · error · ManifestError

The targetPackage specified in the instrumentation manifest

Error message

The targetPackage specified in the instrumentation manifest at {instr_manifest_path} ({target_package_to_instrument}) does not match the package name of the target manifest at {target_manifest_path} ({target_package_name})

What it means

The core consistency check of instrumentation_test_check.py: the targetPackage that the instrumentation manifest wants to instrument must equal the package declared by the target app's manifest. When they differ, ManifestError reports both values and both file paths so the mismatch is obvious.

Source

Thrown at tools/android/instrumentation_test_check.py:91

  if "package" in root.attrib:
    return root.attrib["package"]
  else:
    raise ManifestError("The <manifest> tag in the manifest at %s needs to "
                        "specify the package name using the 'package' "
                        "attribute." % path)


def _ValidateManifestPackageNames(instr_manifest_content, instr_manifest_path,
                                  target_manifest_content,
                                  target_manifest_path):
  """Diff the package names and throw a ManifestError if not identical."""
  target_package_to_instrument = _ExtractTargetPackageToInstrument(
      instr_manifest_content, instr_manifest_path)
  target_package_name = _ExtractTargetPackageName(target_manifest_content,
                                                  target_manifest_path)

  if target_package_to_instrument != target_package_name:
    raise ManifestError(
        "The targetPackage specified in the instrumentation manifest at "
        "{instr_manifest_path} ({target_package_to_instrument}) does not match "
        "the package name of the target manifest at {target_manifest_path} "
        "({target_package_name})".format(
            instr_manifest_path=instr_manifest_path,
            target_package_to_instrument=target_package_to_instrument,
            target_manifest_path=target_manifest_path,
            target_package_name=target_package_name))

  return target_package_to_instrument, target_package_name


def main(unused_argv):
  instr_manifest_path = FLAGS.instrumentation_manifest
  target_manifest_path = FLAGS.target_manifest
  output_path = FLAGS.output
  dirname = os.path.dirname(output_path)
  if not os.path.exists(dirname):

View on GitHub (pinned to e6e199d060)

Solutions

  1. Set android:targetPackage in the instrumentation manifest to exactly the value shown for target_package_name in the error.
  2. If the suffix (e.g. .debug) is correct for your build, update the target manifest's package to match instead.
  3. Regenerate the instrumentation manifest from the same source of truth as the app package to prevent recurrence.

Example fix

<!-- before: instrumentation manifest -->
<instrumentation android:targetPackage="com.example.oldapp" ... />
<!-- target manifest package="com.example.app" -->

<!-- after -->
<instrumentation android:targetPackage="com.example.app" ... />
Defensive patterns

Strategy: validation

Validate before calling

instr_pkg = _ExtractTargetPackageToInstrument(instr_content, instr_path)
target_pkg = _ExtractTargetPackageName(target_content, target_path)
assert instr_pkg == target_pkg, 'targetPackage %s != package %s' % (instr_pkg, target_pkg)

Prevention

When it happens

Trigger: android:targetPackage in the test manifest (e.g. 'com.example.app.test' or an old applicationId) differs from the package attribute of the target manifest (e.g. 'com.example.app').

Common situations: Application id/package renamed without updating test manifests; test manifest copy-pasted from another app; debug builds using an applicationIdSuffix like '.debug' while the manifest keeps the release package.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/702f76761b5f40c9. Report an issue: GitHub.