Skip to content

[fix-finder] Copy-paste bug: targetSdkVersion attribute gated on MinSdkVersion in CreateDynamicFeatureManifest #12250

Description

@github-actions

Problem

In CreateDynamicFeatureManifest.GenerateFeatureManifest, the targetSdkVersion attribute is added inside an if that checks MinSdkVersion instead of TargetSdkVersion. This is a copy-paste error with two consequences:

  1. If MinSdkVersion is set but TargetSdkVersion is null/empty, new XAttribute (androidNS + "targetSdkVersion", TargetSdkVersion) is called with a null value and throws ArgumentNullException.
  2. If MinSdkVersion is empty but TargetSdkVersion is set, the targetSdkVersion attribute is never emitted.

Location

  • File(s): src/Xamarin.Android.Build.Tasks/Tasks/CreateDynamicFeatureManifest.cs
  • Line(s): 65-68

Current Code

if (!MinSdkVersion.IsNullOrEmpty ())
	usesSdk.Add (new XAttribute (androidNS + "minSdkVersion", MinSdkVersion));
if (!MinSdkVersion.IsNullOrEmpty ())
	usesSdk.Add (new XAttribute (androidNS + "targetSdkVersion", TargetSdkVersion));

Suggested Fix

Gate the targetSdkVersion attribute on TargetSdkVersion (matching the minSdkVersion line above it):

if (!MinSdkVersion.IsNullOrEmpty ())
	usesSdk.Add (new XAttribute (androidNS + "minSdkVersion", MinSdkVersion));
if (!TargetSdkVersion.IsNullOrEmpty ())
	usesSdk.Add (new XAttribute (androidNS + "targetSdkVersion", TargetSdkVersion));

Guidelines

  • Project targets netstandard2.0; the existing IsNullOrEmpty () extension method is already used here, so no new APIs are introduced.
  • Follow dotnet/android formatting (tabs, space before ().

Acceptance Criteria

  • The targetSdkVersion attribute is emitted only when TargetSdkVersion is non-empty
  • No exception occurs when MinSdkVersion is set and TargetSdkVersion is null/empty
  • All tests pass
  • No new warnings introduced

Fix-finder metadata

  • Script: 05-general-mistakes
  • Score: 26/30 (actionability: 10, safety: 6, scope: 10)

Generated by Nightly Fix Finder · 59.9 AIC · ⌖ 17.3 AIC · ⊞ 9.4K ·

  • expires on Aug 4, 2026, 2:26 AM UTC

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions