bazelbuild/bazel · error · ManifestError
No <instrumentation> tag containing the targetPackage attrib
Error message
No <instrumentation> tag containing the targetPackage attribute is found in the manifest at %s
What it means
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.
Source
Thrown at tools/android/instrumentation_test_check.py:57
# There might be more than one <instrumentation> tag to use different
# test runners, so we need to extract the targetPackage attribute values
# from all of them and check that they are the same.
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:View on GitHub (pinned to e6e199d060)
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.
Example fix
<!-- before -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<instrumentation android:name="android.test.InstrumentationTestRunner" />
</manifest>
<!-- after -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.app" />
</manifest> Defensive patterns
Strategy: validation
Validate before calling
import xml.etree.ElementTree as ET
def has_instrumentation_target_package(xml_content):
tree = ET.ElementTree(ET.fromstring(xml_content))
key = '{http://schemas.android.com/apk/res/android}targetPackage'
return len(list(tree.iterfind('.//instrumentation[@%s]' % key))) > 0 Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- The <instrumentation> tags in the manifest at %s do not refe
- The <manifest> tag in the manifest at %s needs to specify th
- The targetPackage specified in the instrumentation manifest
- Runfiles failed to resolve {path}
- Proguard failed ({p.returncode})
AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14).
Data as JSON: /api/errors/8b7d8ad52cbe0576.
Report an issue: GitHub.