Skip to content

Commit bdb0766

Browse files
committed
[Xamarin.Android.Build.Utilities] Xamarin can't find NDK 12b because ndk-stack.exe is now ndk-stack.cmd
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=42566 The problem was that we did not UPDATE the ndk-stack.exe property to be ndk-stack.cmd once we had verified that the ndk was valid. This commit adds support for changing the ndk-stack extension to one of the "known" extentions on Windows if it exists.
1 parent 08ff8ba commit bdb0766

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/Xamarin.Android.Build.Utilities/Sdks/AndroidSdkBase.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,24 @@ protected IEnumerable<string> FindExecutableInPath (string executable)
136136

137137
protected IEnumerable<string> FindExecutableInDirectory(string executable, string dir)
138138
{
139-
var pathExt = Environment.GetEnvironmentVariable ("PATHEXT");
140-
var pathExts = pathExt?.Split (new char [] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
141-
142139
if (File.Exists (Path.Combine (dir, (executable))))
143140
yield return dir;
141+
142+
foreach (var exe in Executables (executable))
143+
if (File.Exists (Path.Combine (dir, exe)))
144+
yield return dir;
145+
}
146+
147+
protected IEnumerable<string> Executables (string executable)
148+
{
149+
var pathExt = Environment.GetEnvironmentVariable ("PATHEXT");
150+
var pathExts = pathExt?.Split (new char [] { Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
151+
144152
if (pathExts == null)
145153
yield break;
154+
146155
foreach (var ext in pathExts)
147-
if (File.Exists (Path.Combine (dir, Path.ChangeExtension (executable, ext))))
148-
yield return dir;
156+
yield return Path.ChangeExtension (executable, ext);
149157
}
150158

151159
protected string NullIfEmpty (string s)

src/Xamarin.Android.Build.Utilities/Sdks/AndroidSdkWindows.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class AndroidSdkWindows : AndroidSdkBase
1515
const string XAMARIN_ANDROID_INSTALLER_PATH = @"SOFTWARE\Xamarin\MonoAndroid";
1616
const string XAMARIN_ANDROID_INSTALLER_KEY = "PrivateAndroidSdkPath";
1717

18+
string ndkstack = "ndk-stack.exe";
19+
1820
public override string Adb { get { return "adb.exe"; } }
1921
public override string Android { get { return "android.bat"; } }
2022
public override string Emulator { get { return "emulator.exe"; } }
2123
public override string Monitor { get { return "monitor.bat"; } }
2224
public override string ZipAlign { get { return "zipalign.exe"; } }
2325
public override string JarSigner { get { return "jarsigner.exe"; } }
2426
public override string KeyTool { get { return "keytool.exe"; } }
25-
public override string NdkStack { get { return "ndk-stack.exe"; } }
27+
public override string NdkStack { get { return ndkstack; } }
2628
public override string NdkHostPlatform32Bit { get { return "windows"; } }
2729
public override string NdkHostPlatform64Bit { get { return "windows-x86_64"; } }
2830
public override string Javac { get { return "javac.exe"; } }
@@ -52,6 +54,17 @@ public override string PreferedJavaSdkPath {
5254
}
5355
}
5456

57+
public override void Initialize (string androidSdkPath = null, string androidNdkPath = null, string javaSdkPath = null)
58+
{
59+
base.Initialize (androidSdkPath, androidNdkPath, javaSdkPath);
60+
// we need to look for extensions other than the default .exe|.bat
61+
// google have a habbit of changing them.
62+
foreach (var exe in Executables (NdkStack)) {
63+
if (File.Exists (Path.Combine (AndroidNdkPath, exe)))
64+
ndkstack = exe;
65+
}
66+
}
67+
5568
protected override IEnumerable<string> GetAllAvailableAndroidSdks ()
5669
{
5770
var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine };

0 commit comments

Comments
 (0)