-
Notifications
You must be signed in to change notification settings - Fork 525
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
[trimming] preserve custom views and $(AndroidHttpClientHandlerType)
#8944
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.
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) | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the acw_map.txt file might allow you to map that info back. You will probably need a new file though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to piece together the information with existing files:
customview-map.txt
has 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.aar
Mono.Android-Test.Library.NET.aar
is created based onAndroidResource
files 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.
Closing this in favor of a different approach:
I'll keep this branch around if it's ever useful in the future. |
I think this idea is going to work: |
Fixes: #8797
Context: https://github.com/dotnet/runtime/blob/714a4420805ed53c311b05381c83c88894100fa9/docs/tools/illink/data-formats.md
Here are two cases
TrimMode=full
can break applications:AndroidHttpClientHandlerType
set 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
.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.