bazelbuild/bazel · error · ManifestError

The <instrumentation> tags in the manifest at %s do not refe

Error message

The <instrumentation> tags in the manifest at %s do not reference the same target package: %s

What it means

Thrown by instrumentation_test_check.py when an instrumentation manifest contains multiple <instrumentation android:targetPackage=...> elements whose targetPackage values differ. The checker requires all instrumentation tags to reference one single target package, so it collects the attribute values into a set and rejects size > 1.

Source

Thrown at tools/android/instrumentation_test_check.py:62

def _ExtractTargetPackageToInstrument(xml_content, path):
  """Extract the targetPackage value from the <instrumentation> tag."""

  # https://developer.android.com/guide/topics/manifest/manifest-element.html
  # xmlns:android is the required namespace in an Android manifest.
  tree = ET.ElementTree(ET.fromstring(xml_content))
  package_key = "{http://schemas.android.com/apk/res/android}targetPackage"
  instrumentation_elems = tree.iterfind(
      ".//instrumentation[@{0}]".format(package_key))

  package_names = set(e.attrib[package_key] for e in instrumentation_elems)

  if not package_names:
    raise ManifestError("No <instrumentation> tag containing "
                        "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)

View on GitHub (pinned to e6e199d060)

Solutions

  1. Make all <instrumentation> tags reference the same targetPackage value (the app under test).
  2. Remove redundant instrumentation tags so only one remains.
  3. If testing multiple apps is intended, split into separate android_instrumentation_test targets each with its own manifest.

Example fix

<!-- before: two tags, different packages -->
<instrumentation android:targetPackage="com.example.app" ... />
<instrumentation android:targetPackage="com.example.app2" ... />

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

Strategy: validation

Validate before calling

def instrumentation_targets_unique(xml_content):
    key = '{http://schemas.android.com/apk/res/android}targetPackage'
    tree = ET.ElementTree(ET.fromstring(xml_content))
    names = set(e.attrib[key] for e in tree.iterfind('.//instrumentation[@%s]' % key))
    return len(names) == 1

Prevention

When it happens

Trigger: More than one <instrumentation> tag in the manifest with differing android:targetPackage values (duplicates with the same value are fine — the set collapses them).

Common situations: Merging manifests from multiple test libraries each declaring their own instrumentation tag; copy-pasting an instrumentation block and forgetting to update the package; product-flavor manifest merging pulling in extra tags.

Related errors


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