{"record":{"id":"702f76761b5f40c9","repo":"bazelbuild/bazel","slug":"the-targetpackage-specified-in-the-instrumentation","errorCode":null,"errorMessage":"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} ({target_package_name})","messagePattern":"The targetPackage specified in the instrumentation manifest at (.+?) \\((.+?)\\) does not match the package name of the target manifest at (.+?) \\((.+?)\\)","errorType":"validation","errorClass":"ManifestError","httpStatus":null,"severity":"error","filePath":"tools/android/instrumentation_test_check.py","lineNumber":91,"sourceCode":"  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\ndef _ValidateManifestPackageNames(instr_manifest_content, instr_manifest_path,\n                                  target_manifest_content,\n                                  target_manifest_path):\n  \"\"\"Diff the package names and throw a ManifestError if not identical.\"\"\"\n  target_package_to_instrument = _ExtractTargetPackageToInstrument(\n      instr_manifest_content, instr_manifest_path)\n  target_package_name = _ExtractTargetPackageName(target_manifest_content,\n                                                  target_manifest_path)\n\n  if target_package_to_instrument != target_package_name:\n    raise ManifestError(\n        \"The targetPackage specified in the instrumentation manifest at \"\n        \"{instr_manifest_path} ({target_package_to_instrument}) does not match \"\n        \"the package name of the target manifest at {target_manifest_path} \"\n        \"({target_package_name})\".format(\n            instr_manifest_path=instr_manifest_path,\n            target_package_to_instrument=target_package_to_instrument,\n            target_manifest_path=target_manifest_path,\n            target_package_name=target_package_name))\n\n  return target_package_to_instrument, target_package_name\n\n\ndef main(unused_argv):\n  instr_manifest_path = FLAGS.instrumentation_manifest\n  target_manifest_path = FLAGS.target_manifest\n  output_path = FLAGS.output\n  dirname = os.path.dirname(output_path)\n  if not os.path.exists(dirname):","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/tools/android/instrumentation_test_check.py#L73-L109","documentation":"The core consistency check of instrumentation_test_check.py: the targetPackage that the instrumentation manifest wants to instrument must equal the package declared by the target app's manifest. When they differ, ManifestError reports both values and both file paths so the mismatch is obvious.","triggerScenarios":"android:targetPackage in the test manifest (e.g. 'com.example.app.test' or an old applicationId) differs from the package attribute of the target manifest (e.g. 'com.example.app').","commonSituations":"Application id/package renamed without updating test manifests; test manifest copy-pasted from another app; debug builds using an applicationIdSuffix like '.debug' while the manifest keeps the release package.","solutions":["Set android:targetPackage in the instrumentation manifest to exactly the value shown for target_package_name in the error.","If the suffix (e.g. .debug) is correct for your build, update the target manifest's package to match instead.","Regenerate the instrumentation manifest from the same source of truth as the app package to prevent recurrence."],"exampleFix":"<!-- before: instrumentation manifest -->\n<instrumentation android:targetPackage=\"com.example.oldapp\" ... />\n<!-- target manifest package=\"com.example.app\" -->\n\n<!-- after -->\n<instrumentation android:targetPackage=\"com.example.app\" ... />","handlingStrategy":"validation","validationCode":"instr_pkg = _ExtractTargetPackageToInstrument(instr_content, instr_path)\ntarget_pkg = _ExtractTargetPackageName(target_content, target_path)\nassert instr_pkg == target_pkg, 'targetPackage %s != package %s' % (instr_pkg, target_pkg)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive android:targetPackage from the app's package name in the manifest generation step rather than hardcoding.","When adding applicationIdSuffix flavors, also generate matching instrumentation manifests."],"tags":["android","manifest","instrumentation-test","package-mismatch"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}