{"record":{"id":"35a24b752d4cbc01","repo":"bazelbuild/bazel","slug":"the-instrumentation-tags-in-the-manifest-at-s-d","errorCode":null,"errorMessage":"The <instrumentation> tags in the manifest at %s do not reference the same target package: %s","messagePattern":"The <instrumentation> tags in the manifest at (.+?) do not reference the same target package: (.+?)","errorType":"validation","errorClass":"ManifestError","httpStatus":null,"severity":"error","filePath":"tools/android/instrumentation_test_check.py","lineNumber":62,"sourceCode":"def _ExtractTargetPackageToInstrument(xml_content, path):\n  \"\"\"Extract the targetPackage value from the <instrumentation> tag.\"\"\"\n\n  # https://developer.android.com/guide/topics/manifest/manifest-element.html\n  # xmlns:android is the required namespace in an Android manifest.\n  tree = ET.ElementTree(ET.fromstring(xml_content))\n  package_key = \"{http://schemas.android.com/apk/res/android}targetPackage\"\n  instrumentation_elems = tree.iterfind(\n      \".//instrumentation[@{0}]\".format(package_key))\n\n  package_names = set(e.attrib[package_key] for e in instrumentation_elems)\n\n  if not package_names:\n    raise ManifestError(\"No <instrumentation> tag containing \"\n                        \"the targetPackage attribute is found in the \"\n                        \"manifest at %s\" % path)\n\n  if len(package_names) > 1:\n    raise ManifestError(\n        \"The <instrumentation> tags in the manifest at %s do not \"\n        \"reference the same target package: %s\" % (path, list(package_names)))\n\n  return package_names.pop()\n\n\ndef _ExtractTargetPackageName(xml_content, path):\n  \"\"\"Extract the package name value from the root <manifest> tag.\"\"\"\n  tree = ET.ElementTree(ET.fromstring(xml_content))\n  root = tree.getroot()\n  if \"package\" in root.attrib:\n    return root.attrib[\"package\"]\n  else:\n    raise ManifestError(\"The <manifest> tag in the manifest at %s needs to \"\n                        \"specify the package name using the 'package' \"\n                        \"attribute.\" % path)\n\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/android/instrumentation_test_check.py#L44-L80","documentation":"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.","triggerScenarios":"More than one <instrumentation> tag in the manifest with differing android:targetPackage values (duplicates with the same value are fine — the set collapses them).","commonSituations":"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.","solutions":["Make all <instrumentation> tags reference the same targetPackage value (the app under test).","Remove redundant instrumentation tags so only one remains.","If testing multiple apps is intended, split into separate android_instrumentation_test targets each with its own manifest."],"exampleFix":"<!-- before: two tags, different packages -->\n<instrumentation android:targetPackage=\"com.example.app\" ... />\n<instrumentation android:targetPackage=\"com.example.app2\" ... />\n\n<!-- after -->\n<instrumentation android:targetPackage=\"com.example.app\" ... />","handlingStrategy":"validation","validationCode":"def instrumentation_targets_unique(xml_content):\n    key = '{http://schemas.android.com/apk/res/android}targetPackage'\n    tree = ET.ElementTree(ET.fromstring(xml_content))\n    names = set(e.attrib[key] for e in tree.iterfind('.//instrumentation[@%s]' % key))\n    return len(names) == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one <instrumentation> tag per test manifest.","After manifest merges, verify all instrumentation tags still reference one target package."],"tags":["android","manifest","instrumentation-test","xml"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}