Add improved Android NDK detection and prevent exception

#614
This commit is contained in:
Wojtek Figat
2021-08-31 10:40:38 +02:00
parent b29e1e9878
commit df10581bb2

View File

@@ -18,7 +18,7 @@ namespace Flax.Build.Platforms
public static readonly AndroidNdk Instance = new AndroidNdk();
/// <inheritdoc />
public override TargetPlatform[] Platforms => new []
public override TargetPlatform[] Platforms => new[]
{
TargetPlatform.Windows,
TargetPlatform.Linux,
@@ -63,20 +63,37 @@ namespace Flax.Build.Platforms
{
Log.Warning(string.Format("Specified Android NDK folder in ANDROID_NDK env variable doesn't exist ({0})", sdkPath));
}
if (!string.IsNullOrEmpty(sdkPath))
if (!string.IsNullOrEmpty(sdkPath) && Directory.Exists(sdkPath))
{
var lines = File.ReadAllLines(Path.Combine(sdkPath, "source.properties"));
if (lines.Length > 1)
var sourceProperties = Path.Combine(sdkPath, "source.properties");
if (File.Exists(sourceProperties))
{
var ver = lines[1].Substring(lines[1].IndexOf(" = ", StringComparison.Ordinal) + 2);
if (Version.TryParse(ver, out var v))
var lines = File.ReadAllLines(sourceProperties);
if (lines.Length > 1)
{
RootPath = sdkPath;
Version = v;
IsValid = true;
Log.Info(string.Format("Found Android NDK {1} at {0}", RootPath, Version));
var ver = lines[1].Substring(lines[1].IndexOf(" = ", StringComparison.Ordinal) + 2);
if (Version.TryParse(ver, out var v))
{
Version = v;
IsValid = true;
}
}
}
else if (Version.TryParse(Path.GetFileName(sdkPath), out var v))
{
Version = v;
IsValid = true;
}
else
{
Log.Warning(string.Format("Failed to detect Android NDK version ({0})", sdkPath));
}
}
if (IsValid)
{
RootPath = sdkPath;
IsValid = true;
Log.Info(string.Format("Found Android NDK {1} at {0}", RootPath, Version));
}
}
}