[trimming] preserve custom views and $(AndroidHttpClientHandlerType)#8944
Closed
jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
Closed
[trimming] preserve custom views and $(AndroidHttpClientHandlerType)#8944jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
$(AndroidHttpClientHandlerType)#8944jonathanpeppers wants to merge 1 commit intodotnet:mainfrom
Conversation
Fixes: dotnet#8797 Context: https://github.com/dotnet/runtime/blob/714a4420805ed53c311b05381c83c88894100fa9/docs/tools/illink/data-formats.md Context: Here are two cases `TrimMode=full` can break applications: * `AndroidHttpClientHandlerType` set to a custom type * Custom views (Android `.xml`) that are not referenced in C# code For either of these cases, the traditional approach in Xamarin.Android would have been to author a trimmer step to preserve these types. However, thinking about NativeAOT in the future, it is more "future-proof" to write an MSBuild task that generates trimmer `.xml` to preserve these types. This same XML file could be passed to the NativeAOT trimmer (`Ilc`). If we had a custom trimmer step, we would have to reimplement the same logic for the NativeAOT trimmer. This is WIP as custom views are not yet preserved.
jonathanpeppers
commented
May 14, 2024
Comment on lines
+47
to
+60
| var customViewMap = MonoAndroidHelper.LoadCustomViewMapFile (BuildEngine4, CustomViewMapFile); | ||
| foreach (var pair in customViewMap) { | ||
| index = pair.Key.IndexOf (','); | ||
| if (index == -1) | ||
| continue; | ||
|
|
||
| typeName = pair.Key.Substring (0, index).Trim (); | ||
| assemblyName = pair.Key.Substring (index + 1).Trim (); | ||
|
|
||
| linker.Add (new XElement ("assembly", | ||
| new XAttribute ("fullname", assemblyName), | ||
| new XElement ("type", new XAttribute ("fullname", typeName), ctor) | ||
| )); | ||
| } |
Member
Author
There was a problem hiding this comment.
This code doesn't work yet, as the file contains:
mono.android_test.library.CustomTextView;D:\src\xamarin-android\tests\Mono.Android-Tests\Runtime-Microsoft.Android.Sdk\obj\Release\net9.0-android\lp\6\jl\res\layout\upper_lower_custom.xml
mono.android_test.library.CustomTextView;obj\Release\net9.0-android\res\layout\upper_lower_custom.xml
Mono.Android_Test.Library.CustomTextView;D:\src\xamarin-android\tests\Mono.Android-Tests\Runtime-Microsoft.Android.Sdk\obj\Release\net9.0-android\lp\6\jl\res\layout\upper_lower_custom.xml
Mono.Android_Test.Library.CustomTextView;obj\Release\net9.0-android\res\layout\upper_lower_custom.xml
Mono.Android_Test.Library.CustomTextView;obj\Release\net9.0-android\res\layout\uppercase_custom.xml
I need the full type name like Mono.Android_Test.Library.CustomTextView, Mono.Android_Test.Library.
Contributor
There was a problem hiding this comment.
Using the acw_map.txt file might allow you to map that info back. You will probably need a new file though.
Member
Author
There was a problem hiding this comment.
I tried to piece together the information with existing files:
customview-map.txthas an entry with a type name and file name likeupper_lower_custom.xml<ConvertResourcesCases/>has$(MonoAndroidResDirIntermediate);@(_LibraryResourceDirectories)@(_LibraryResourceDirectories)hasOriginalFile = D:\src\xamarin-android\tests\Mono.Android-Tests\Mono.Android-Test.Library\bin\Release\net9.0-android\Mono.Android-Test.Library.NET.aarMono.Android-Test.Library.NET.aaris created based onAndroidResourcefiles inMono.Android-Test.Library.NET.dll
So, it doesn't seem like we even have data to map back to the assembly name. I'll keep thinking about this one.
Member
Author
|
Closing this in favor of a different approach:
I'll keep this branch around if it's ever useful in the future. |
Member
Author
|
I think this idea is going to work: |
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.
Fixes: #8797
Context: https://github.com/dotnet/runtime/blob/714a4420805ed53c311b05381c83c88894100fa9/docs/tools/illink/data-formats.md
Here are two cases
TrimMode=fullcan break applications:AndroidHttpClientHandlerTypeset to a custom typeCustom views (Android
.xml) that are not referenced in C# codeFor either of these cases, the traditional approach in Xamarin.Android would have been to author a trimmer step to preserve these types.
However, thinking about NativeAOT in the future, it is more "future-proof" to write an MSBuild task that generates trimmer
.xmlto preserve these types. This same XML file could be passed to the NativeAOT trimmer (Ilc). If we had a custom trimmer step, we would have to reimplement the same logic for the NativeAOT trimmer.This is WIP as custom views are not yet preserved.