Problem
Three internal methods in AndroidSdk.cs use #pragma warning disable CS0618 to suppress obsolete-usage warnings when accessing the AndroidToolsPath property. The property is marked [Obsolete("Use GetCommandLineToolsPaths().")], but these callsites only need the underlying path value (<sdk>/tools), which can be computed directly via Path.Combine(AndroidSdkPath, "tools") — eliminating the need for the pragma suppressions entirely.
Location
- File:
src/Xamarin.AndroidTools/AndroidSdk.cs
- Lines: 558–560, 581–583, 609–611
Current Code
GetZipAlignPath() (lines 558–560):
#pragma warning disable CS0618 // Type or member is obsolete
var old = Path.Combine (GetShortPathName (AndroidToolsPath), zipAlign);
#pragma warning restore CS0618
GetApkSignerPath() (lines 581–583):
#pragma warning disable CS0618 // Type or member is obsolete
var old = Path.Combine (GetShortPathName (AndroidToolsPath), apkSigner);
#pragma warning restore CS0618
GetFallbackApkAnalyzerPath() (lines 609–611):
#pragma warning disable CS0618 // Type or member is obsolete
var apkanalyzerPath = Path.Combine (AndroidSdk.AndroidToolsPath, "bin", apkanalyzer);
#pragma warning restore CS0618
Suggested Fix
Replace each usage of the obsolete AndroidToolsPath property with direct path construction using Path.Combine (AndroidSdkPath, "tools"). The AndroidToolsPath property is set to exactly Path.Combine (AndroidSdkPath, "tools") in Refresh() (line 69), so this is a semantically identical substitution.
GetZipAlignPath():
var old = Path.Combine (GetShortPathName (Path.Combine (AndroidSdkPath, "tools")), zipAlign);
GetApkSignerPath():
var old = Path.Combine (GetShortPathName (Path.Combine (AndroidSdkPath, "tools")), apkSigner);
GetFallbackApkAnalyzerPath():
var apkanalyzerPath = Path.Combine (AndroidSdkPath, "tools", "bin", apkanalyzer);
Guidelines
- The project targets
netstandard2.0 with LangVersion 12 — all APIs used above (Path.Combine with 3–4 args) are available on netstandard2.0
- Do not modify the
[Obsolete] declarations themselves or the Refresh() method pragma block (lines 58–96) — those serve different purposes
- Do not remove or change the fallback logic (the
File.Exists checks) — only change how the path string is obtained
- Follow Mono formatting style: space before
(, tabs for indentation
Acceptance Criteria
Fix-finder metadata
- Script:
02-obsolete-api-usage
- Score:
27/30 (actionability: 9, safety: 9, scope: 9)
Generated by Nightly Fix Finder · ● 18.6M · ◷
Problem
Three internal methods in
AndroidSdk.csuse#pragma warning disable CS0618to suppress obsolete-usage warnings when accessing theAndroidToolsPathproperty. The property is marked[Obsolete("Use GetCommandLineToolsPaths().")], but these callsites only need the underlying path value (<sdk>/tools), which can be computed directly viaPath.Combine(AndroidSdkPath, "tools")— eliminating the need for the pragma suppressions entirely.Location
src/Xamarin.AndroidTools/AndroidSdk.csCurrent Code
GetZipAlignPath()(lines 558–560):GetApkSignerPath()(lines 581–583):GetFallbackApkAnalyzerPath()(lines 609–611):Suggested Fix
Replace each usage of the obsolete
AndroidToolsPathproperty with direct path construction usingPath.Combine (AndroidSdkPath, "tools"). TheAndroidToolsPathproperty is set to exactlyPath.Combine (AndroidSdkPath, "tools")inRefresh()(line 69), so this is a semantically identical substitution.GetZipAlignPath():GetApkSignerPath():GetFallbackApkAnalyzerPath():Guidelines
netstandard2.0withLangVersion 12— all APIs used above (Path.Combinewith 3–4 args) are available onnetstandard2.0[Obsolete]declarations themselves or theRefresh()method pragma block (lines 58–96) — those serve different purposesFile.Existschecks) — only change how the path string is obtained(, tabs for indentationAcceptance Criteria
#pragma warning disable/restore CS0618pairs aroundAndroidToolsPathusage (lines 558–560, 581–583, 609–611) are removedPath.Combine (AndroidSdkPath, "tools")instead ofAndroidToolsPathFix-finder metadata
02-obsolete-api-usage27/30(actionability:9, safety:9, scope:9)