Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public string[] AllAndroidSdks {
var dirs = new List<string?> ();
dirs.Add (AndroidSdkPath);
dirs.AddRange (GetAllAvailableAndroidSdks ());
allAndroidSdks = dirs.Where (d => ValidateAndroidSdkLocation (d))
allAndroidSdks = dirs.Where (d => ValidateAndroidSdkLocation ("AllAndroidSdks", d))
.Select (d => d!)
.Distinct ()
.ToArray ();
Expand Down Expand Up @@ -102,15 +102,15 @@ public virtual void Initialize (string? androidSdkPath = null, string? androidNd
NdkStack = GetExecutablePath (AndroidNdkPath, NdkStack);
}

static string? GetValidPath (Func<string?, bool> pathValidator, string? ctorParam, Func<string?> getPreferredPath, Func<IEnumerable<string>> getAllPaths)
static string? GetValidPath (Func<string, string?, bool> pathValidator, string? ctorParam, Func<string?> getPreferredPath, Func<IEnumerable<string>> getAllPaths)
{
if (pathValidator (ctorParam))
if (pathValidator ("constructor param", ctorParam))
return ctorParam;
ctorParam = getPreferredPath ();
if (pathValidator (ctorParam))
if (pathValidator ("preferred path", ctorParam))
return ctorParam;
foreach (var path in getAllPaths ()) {
if (pathValidator (path)) {
if (pathValidator ("all paths", path)) {
return path;
}
}
Expand All @@ -119,18 +119,18 @@ public virtual void Initialize (string? androidSdkPath = null, string? androidNd

string? GetValidNdkPath (string? ctorParam)
{
if (ValidateAndroidNdkLocation (ctorParam))
if (ValidateAndroidNdkLocation ("constructor param", ctorParam))
return ctorParam;
if (AndroidSdkPath != null) {
string bundle = FindBestNDK (AndroidSdkPath);
if (Directory.Exists (bundle) && ValidateAndroidNdkLocation (bundle))
if (Directory.Exists (bundle) && ValidateAndroidNdkLocation ("within Android SDK", bundle))
return bundle;
}
ctorParam = PreferedAndroidNdkPath;
if (ValidateAndroidNdkLocation (ctorParam))
if (ValidateAndroidNdkLocation ("preferred path", ctorParam))
return ctorParam;
foreach (var path in GetAllAvailableAndroidNdks ()) {
if (ValidateAndroidNdkLocation (path))
if (ValidateAndroidNdkLocation ("all paths", path))
return path;
}
return null;
Expand Down Expand Up @@ -255,31 +255,47 @@ IEnumerable<string> GetJavaSdkPaths ()
/// <summary>
/// Checks that a value is the location of an Android SDK.
/// </summary>
public bool ValidateAndroidSdkLocation ([NotNullWhen (true)] string? loc)
public bool ValidateAndroidSdkLocation (string locator, [NotNullWhen (true)] string? loc)
{
bool result = !string.IsNullOrEmpty (loc) && ProcessUtils.FindExecutablesInDirectory (Path.Combine (loc, "platform-tools"), Adb).Any ();
Logger (TraceLevel.Verbose, $"{nameof (ValidateAndroidSdkLocation)}: `{loc}`, result={result}");
bool result = !string.IsNullOrEmpty (loc);
if (result) {
bool foundAdb = false;
foreach (var p in ProcessUtils.FindExecutablesInDirectory (Path.Combine (loc!, "platform-tools"), Adb)) {
Logger (TraceLevel.Verbose, $"{nameof (ValidateAndroidSdkLocation)}: for locator={locator}, path=`{loc}`, found adb `{p}`");
foundAdb = true;
}
result = foundAdb;
}
Logger (TraceLevel.Verbose, $"{nameof (ValidateAndroidSdkLocation)}: for locator={locator}, path=`{loc}`, result={result}");
return result;
}

/// <summary>
/// Checks that a value is the location of a Java SDK.
/// </summary>
public virtual bool ValidateJavaSdkLocation ([NotNullWhen (true)] string? loc)
public virtual bool ValidateJavaSdkLocation (string locator, [NotNullWhen (true)] string? loc)
{
bool result = !string.IsNullOrEmpty (loc) && ProcessUtils.FindExecutablesInDirectory (Path.Combine (loc, "bin"), JarSigner).Any ();
Logger (TraceLevel.Verbose, $"{nameof (ValidateJavaSdkLocation)}: `{loc}`, result={result}");
bool result = !string.IsNullOrEmpty (loc);
if (result) {
bool foundSigner = false;
foreach (var p in ProcessUtils.FindExecutablesInDirectory (Path.Combine (loc!, "bin"), JarSigner)) {
Logger (TraceLevel.Verbose, $"{nameof (ValidateJavaSdkLocation)}: for locator={locator}, path=`{loc}`, found jarsigner `{p}`");
foundSigner = true;
}
result = foundSigner;
}
Logger (TraceLevel.Verbose, $"{nameof (ValidateJavaSdkLocation)}: locator={locator}, path=`{loc}`, result={result}");
return result;
}

/// <summary>
/// Checks that a value is the location of an Android SDK.
/// </summary>
public bool ValidateAndroidNdkLocation ([NotNullWhen (true)] string? loc)
public bool ValidateAndroidNdkLocation (string locator, [NotNullWhen (true)] string? loc)
{
bool result = !string.IsNullOrEmpty (loc) &&
ProcessUtils.FindExecutablesInDirectory (loc!, NdkStack).Any ();
Logger (TraceLevel.Verbose, $"{nameof (ValidateAndroidNdkLocation)}: `{loc}`, result={result}");
Logger (TraceLevel.Verbose, $"{nameof (ValidateAndroidNdkLocation)}: for locator={locator}, path=`{loc}`, result={result}");
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override string? PreferedAndroidSdkPath {
if (androidEl != null) {
var path = (string?)androidEl.Attribute ("path");

if (ValidateAndroidSdkLocation (path))
if (ValidateAndroidSdkLocation ("preferred path", path))
return path;
}
return null;
Expand All @@ -66,7 +66,7 @@ public override string? PreferedAndroidNdkPath {
if (androidEl != null) {
var path = (string?)androidEl.Attribute ("path");

if (ValidateAndroidNdkLocation (path))
if (ValidateAndroidNdkLocation ("preferred path", path))
return path;
}
return null;
Expand All @@ -81,7 +81,7 @@ public override string? PreferedJavaSdkPath {
if (javaEl != null) {
var path = (string?)javaEl.Attribute ("path");

if (ValidateJavaSdkLocation (path))
if (ValidateJavaSdkLocation ("preferred path", path))
return path;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected override IEnumerable<string> GetAllAvailableAndroidNdks ()
foreach (var basePath in new string [] {xamarin_private, android_default, vs_default, vs_default32bit, vs_2017_default, cdrive_default})
if (Directory.Exists (basePath))
foreach (var dir in Directory.GetDirectories (basePath, "android-ndk-r*"))
if (ValidateAndroidNdkLocation (dir))
if (ValidateAndroidNdkLocation ("Windows known NDK path", dir))
yield return dir;

foreach (var dir in base.GetAllAvailableAndroidNdks ()) {
Expand Down