[Xamarin.Android.Build.Tasks] <GenerateJavaStubs/> should open readonly in some cases#8129
Merged
jonathanpeppers merged 1 commit intodotnet:mainfrom Jun 14, 2023
Conversation
…ly in some cases
I was investigating a failure building Android projects in `Release`
mode inside VS Mac:
Task "GenerateJavaStubs"
Failed to read '/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-arm/8.0.0-preview.5.23280.8/runtimes/android-arm/lib/net8.0/Microsoft.CSharp.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
System.UnauthorizedAccessException: Access to the path '/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-arm/8.0.0-preview.5.23280.8/runtimes/android-arm/lib/net8.0/Microsoft.CSharp.dll' is denied.
---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
at Interop.CheckIo(Error error, String path, Boolean isDirError)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Func`4 createOpenException)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/cecil/Mono.Cecil/ModuleDefinition.cs:line 1103
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.LoadFromMemoryMappedFile(String file, ReaderParameters options) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 184
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(String file) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:line 169
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.0-preview.5.312/tools/Xamarin.Android.Common.targets(1513,3): error XA0009: Error while loading assembly: '/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-arm/8.0.0-preview.5.23280.8/runtimes/android-arm/lib/net8.0/Microsoft.CSharp.dll'.
Done executing task "GenerateJavaStubs" -- FAILED.
I noticed `DirectoryAssemblyResolver.LoadFromMemoryMappedFile()` was
not opening the file in read-only mode for `Debug` builds.
In 8bc7a3e, we added "marshal methods" support that unconditionally
enables `ReaderParameters.ReadWrite`.
We should be able to toggle these settings only when "marshal methods"
is enabled:
var readerParams = new ReaderParameters();
if (useMarshalMethods) {
readerParams.ReadWrite = true;
readerParams.InMemory = true;
}
This should improve performance for `Debug` builds, and avoid opening
files in read/write mode.
grendello
approved these changes
Jun 14, 2023
dellis1972
approved these changes
Jun 14, 2023
grendello
added a commit
to grendello/xamarin-android
that referenced
this pull request
Jun 15, 2023
* main: [Xamarin.Android.Build.Tasks] <GenerateJavaStubs/> should open readonly in some cases (dotnet#8129) [Mono.Android] suppress/solve more illink warnings (dotnet#8063)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was investigating a failure building Android projects in
Releasemode inside VS Mac:I noticed
DirectoryAssemblyResolver.LoadFromMemoryMappedFile()was not opening the file in read-only mode forDebugbuilds.In 8bc7a3e, we added "marshal methods" support that unconditionally enables
ReaderParameters.ReadWrite.We should be able to toggle these settings only when "marshal methods" is enabled:
This should improve performance for
Debugbuilds, and avoid opening files in read/write mode.