From df10581bb25daf54b3a15831f04ddfdb895cfcd3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 31 Aug 2021 10:40:38 +0200 Subject: [PATCH] Add improved Android NDK detection and prevent exception #614 --- .../Platforms/Android/AndroidNdk.cs | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Source/Tools/Flax.Build/Platforms/Android/AndroidNdk.cs b/Source/Tools/Flax.Build/Platforms/Android/AndroidNdk.cs index c8443729d..04c220934 100644 --- a/Source/Tools/Flax.Build/Platforms/Android/AndroidNdk.cs +++ b/Source/Tools/Flax.Build/Platforms/Android/AndroidNdk.cs @@ -18,7 +18,7 @@ namespace Flax.Build.Platforms public static readonly AndroidNdk Instance = new AndroidNdk(); /// - 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)); } } }