{"record":{"id":"8b7d8ad52cbe0576","repo":"bazelbuild/bazel","slug":"no-instrumentation-tag-containing-the-targetpack","errorCode":null,"errorMessage":"No <instrumentation> tag containing the targetPackage attribute is found in the manifest at %s","messagePattern":"No <instrumentation> tag containing the targetPackage attribute is found in the manifest at (.+?)","errorType":"validation","errorClass":"ManifestError","httpStatus":null,"severity":"error","filePath":"tools/android/instrumentation_test_check.py","lineNumber":57,"sourceCode":"\n\n# There might be more than one <instrumentation> tag to use different\n# test runners, so we need to extract the targetPackage attribute values\n# from all of them and check that they are the same.\ndef _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:","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/android/instrumentation_test_check.py#L39-L75","documentation":"Thrown by tools/android/instrumentation_test_check.py while validating an instrumentation test manifest. It searches for <instrumentation> elements carrying the Android-namespaced targetPackage attribute; if none is found, ManifestError is raised with the manifest path.","triggerScenarios":"The instrumentation manifest XML parsed by _ExtractTargetPackageToInstrument contains no <instrumentation> tag, or the tag exists but omits android:targetPackage (e.g. only android:name is set).","commonSituations":"Hand-written test manifest missing the instrumentation block; targetPackage written without the android: namespace so ElementTree does not match '{http://schemas.android.com/apk/res/android}targetPackage'; manifest trimmed during a refactor.","solutions":["Add <instrumentation android:name=\"...\" android:targetPackage=\"<target app package>\" /> inside <manifest>.","Verify the attribute uses the android: namespace prefix and that xmlns:android is declared on the root.","Check that the manifest passed via --instrumentation_manifest is the test manifest, not the app manifest."],"exampleFix":"<!-- before -->\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\">\n  <instrumentation android:name=\"android.test.InstrumentationTestRunner\" />\n</manifest>\n\n<!-- after -->\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\">\n  <instrumentation android:name=\"android.test.InstrumentationTestRunner\"\n      android:targetPackage=\"com.example.app\" />\n</manifest>","handlingStrategy":"validation","validationCode":"import xml.etree.ElementTree as ET\n\ndef has_instrumentation_target_package(xml_content):\n    tree = ET.ElementTree(ET.fromstring(xml_content))\n    key = '{http://schemas.android.com/apk/res/android}targetPackage'\n    return len(list(tree.iterfind('.//instrumentation[@%s]' % key))) > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include a lint step that parses instrumentation manifests and asserts the android:targetPackage attribute exists.","Declare xmlns:android on the manifest root whenever editing by hand."],"tags":["android","manifest","instrumentation-test","xml"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}