bazelbuild/bazel · error · ManifestError

The <manifest> tag in the manifest at %s needs to specify th

Error message

The <manifest> tag in the manifest at %s needs to specify the package name using the 'package' attribute.

What it means

Thrown by instrumentation_test_check.py's _ExtractTargetPackageName when the target app's manifest root <manifest> element has no 'package' attribute. The checker needs the app's package name to compare it against the instrumentation manifest's targetPackage, so the attribute is mandatory.

Source

Thrown at tools/android/instrumentation_test_check.py:76

                        "the targetPackage attribute is found in the "
                        "manifest at %s" % path)

  if len(package_names) > 1:
    raise ManifestError(
        "The <instrumentation> tags in the manifest at %s do not "
        "reference the same target package: %s" % (path, list(package_names)))

  return package_names.pop()


def _ExtractTargetPackageName(xml_content, path):
  """Extract the package name value from the root <manifest> tag."""
  tree = ET.ElementTree(ET.fromstring(xml_content))
  root = tree.getroot()
  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} "

View on GitHub (pinned to e6e199d060)

Solutions

  1. Add package="com.example.app" to the root <manifest> element of the target manifest.
  2. Verify you are pointing --target_manifest at the real app manifest, not a fragment or the test manifest.
  3. If the manifest is generated, fix the generation template to emit the package attribute.

Example fix

<!-- before -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- after -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">
Defensive patterns

Strategy: validation

Validate before calling

root = ET.fromstring(target_manifest_content)
assert 'package' in root.attrib, 'target manifest missing package attribute'

Prevention

When it happens

Trigger: The manifest supplied as the target manifest has a <manifest> root without package="..." — for example it only declares uses-permission elements or relies on Gradle-style namespace injection.

Common situations: Passing the wrong file as --target_manifest; manifests generated without package (newer AGP moves package to build.gradle namespace); a trimmed placeholder manifest used in tests.

Related errors


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