-
Notifications
You must be signed in to change notification settings - Fork 31
[macOS] fix DirectoryNotFoundException on clean systems #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@PureWeen was hitting a problem building a .NET 6 app on macOS: Task "ResolveSdks" ... at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound) at System.IO.Enumeration.FileSystemEnumerator`1.Init() at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerableFactory.UserDirectories(String directory, String expression, EnumerationOptions options) at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) at Xamarin.Android.Tools.AndroidSdkBase.FindBestNDK(String androidSdkPath) in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs:line 172 at Xamarin.Android.Tools.AndroidSdkBase.GetAllAvailableAndroidNdks()+MoveNext() in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs:line 164 at Xamarin.Android.Tools.AndroidSdkBase.GetValidNdkPath(String ctorParam) in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs:line 128 at Xamarin.Android.Tools.AndroidSdkBase.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs:line 71 at Xamarin.Android.Tools.AndroidSdkInfo..ctor(Action`2 logger, String androidSdkPath, String androidNdkPath, String javaSdkPath) in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs:line 18 at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshAndroidSdk(String sdkPath, String ndkPath, String javaPath, TaskLoggingHelper logHelper) at Xamarin.Android.Tasks.ResolveSdks.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/builder/azdo/_work/278/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 This was a relatively new Mac, that didn't have an Android NDK installed at all. A way to workaround the problem was to create a directory that did not exist: mkdir -p ~/Library/Android/sdk It appears this problem was introduced in b2d9fdf: * `~/Library/Android/sdk` is returned form `GetAllAvailableAndroidNdks()`: https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs#L113-L115 * `GetAllAvailableAndroidNdks()` calls `GetAllAvailableAndroidSdks()` looking for any `ndk-bundle` folders it can find. * `FindBestNDK()` is passed a directory that doesn't exist, and the `Directory.EnumerateDirectories()` call will throw: https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs#L172 The fix here is to check `Directory.Exists()` in `FindBestNDK()`, as the values from `GetSdkFromEnvironmentVariables()` may not exist either. I was able to add a test for this scenario by adding an invalid directory to `$ANDROID_HOME`.
@PureWeen was hitting a problem building a .NET 6 app on macOS: Task "ResolveSdks" ... at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound) at System.IO.Enumeration.FileSystemEnumerator`1.Init() at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options) at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized) at System.IO.Enumeration.FileSystemEnumerableFactory.UserDirectories(String directory, String expression, EnumerationOptions options) at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) at Xamarin.Android.Tools.AndroidSdkBase.FindBestNDK(String androidSdkPath) at Xamarin.Android.Tools.AndroidSdkBase.GetAllAvailableAndroidNdks()+MoveNext() at Xamarin.Android.Tools.AndroidSdkBase.GetValidNdkPath(String ctorParam) at Xamarin.Android.Tools.AndroidSdkBase.Initialize(String androidSdkPath, String androidNdkPath, String javaSdkPath) at Xamarin.Android.Tools.AndroidSdkInfo..ctor(Action`2 logger, String androidSdkPath, String androidNdkPath, String javaSdkPath) at Xamarin.Android.Tasks.MonoAndroidHelper.RefreshAndroidSdk(String sdkPath, String ndkPath, String javaPath, TaskLoggingHelper logHelper) at Xamarin.Android.Tasks.ResolveSdks.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() This was a relatively new Mac which didn't have an Android NDK installed. A way to workaround the problem was to create a directory that was being checked for: mkdir -p ~/Library/Android/sdk It appears this problem was introduced in b2d9fdf, as: 1. `~/Library/Android/sdk` is returned from [`GetAllAvailableAndroidNdks()`][0] 2. `GetAllAvailableAndroidNdks()` calls `GetAllAvailableAndroidSdks()` looking for any `ndk-bundle` folders it can find. 3. `FindBestNDK()` is passed a directory that doesn't exist, and the `Directory.EnumerateDirectories()` call [throw][1]. The fix here is to update `FindBestNDK()` to check `Directory.Exists()` before trying to traverse the directory `androidSdkPath`, as the values from `GetSdkFromEnvironmentVariables()` may not exist either. I was able to add a test for this scenario by adding an invalid directory to `$ANDROID_HOME`. [0]: https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs#L113-L115 [1]: https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs#L172
i create this directory and the appliction work for me. Thanks |
…193) Changes: mono/mono.posix@e1269a5...d8994ca * mono/mono.posix@d8994ca: Remove Windows support completely for now Fixes an issue in which Mono.Unix would try to resolve `libc` P/Invokes by looking for the `msvcrt` library on Unix machines. * mono/mono.posix@74d504f: Fix yaml template path * mono/mono.posix@127cf9e: [build] Don't rebuild managed code on packaging time on Windows Changes: dotnet/android-libzipsharp@2.0.4...2.0.7 * dotnet/android-libzipsharp@98e9173: Bump version to 2.0.7 * dotnet/android-libzipsharp@6e1e1b3: Localized file check-in by OneLocBuild Task: Build definition ID 11678: Build ID 6581869 (#119) * dotnet/android-libzipsharp@1c05430: LEGO: Merge pull request 118 * dotnet/android-libzipsharp@06d44d8: Localized file check-in by OneLocBuild Task: Build definition ID 11678: Build ID 6570668 (#117) * dotnet/android-libzipsharp@37f3894: LEGO: Merge pull request 116 * dotnet/android-libzipsharp@6c0edc5: Update libzip and zlib submodules (#115) * dotnet/android-libzipsharp@acd9a54: [Localization] Switch from xlf to resx files (#112) * dotnet/android-libzipsharp@3cece80: LEGO: Merge pull request 114 * dotnet/android-libzipsharp@fe336b4: LEGO: Merge pull request 113 * dotnet/android-libzipsharp@9aee99a: [Localization] Add OneLocBuild job (#111) * dotnet/android-libzipsharp@bdfa9f8: Bump Mono.Unix to 7.1.0-final.1.21458.1 (#110)
@PureWeen was hitting a problem building a .NET 6 app on macOS:
This was a relatively new Mac, that didn't have an Android NDK
installed at all.
A way to workaround the problem was to create a directory that did not
exist:
It appears this problem was introduced in b2d9fdf:
~/Library/Android/sdk
is returned formGetAllAvailableAndroidNdks()
:https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkUnix.cs#L113-L115
GetAllAvailableAndroidNdks()
callsGetAllAvailableAndroidSdks()
looking for any
ndk-bundle
folders it can find.FindBestNDK()
is passed a directory that doesn't exist, and theDirectory.EnumerateDirectories()
call will throw:https://github.com/xamarin/xamarin-android-tools/blob/b2d9fdf8782875ffb63da48cf8e0b385b04f7c25/src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs#L172
The fix here is to check
Directory.Exists()
inFindBestNDK()
, asthe values from
GetSdkFromEnvironmentVariables()
may not existeither.
I was able to add a test for this scenario by adding an invalid
directory to
$ANDROID_HOME
.