-
Notifications
You must be signed in to change notification settings - Fork 533
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
How to exclude some libraries to be trimmed in .NET 8 for Android, not MAUI? #8975
Comments
@FANMixco take a look through these documents, it should help https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNet.md#linker-illink |
Also based on https://learn.microsoft.com/en-gb/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-8-0#trimming-granularity you probably need to set TrimMode to partial ( |
I tried the partial one, but the error persists: <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>partial</TrimMode>
<PublishTrimmed>True</PublishTrimmed>
<RunAOTCompilation>True</RunAOTCompilation>
<AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>link</TrimMode>
<RunAOTCompilation>True</RunAOTCompilation>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="Xamarin-MaterialSearchBar" RootMode="CopyUsed" />
</ItemGroup> |
If I use <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>CopyUsed</TrimMode>
<PublishTrimmed>True</PublishTrimmed>
<RunAOTCompilation>True</RunAOTCompilation>
<AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>link</TrimMode>
<RunAOTCompilation>True</RunAOTCompilation>
</PropertyGroup> |
I did the following changes:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>CopyUsed</TrimMode>
<PublishTrimmed>True</PublishTrimmed>
<RunAOTCompilation>False</RunAOTCompilation>
<AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>link</TrimMode>
<RunAOTCompilation>False</RunAOTCompilation>
</PropertyGroup> But I don't think it's working at all since the library is still being deleted:
This doesn't happen if I avoid trimming it, but then the app doubles its size. Any suggestions? |
@FANMixco Looks like the valid values for I'm not 100% what each of those do but the code for the process is at https://github.com/dotnet/runtime/blob/main/src/tools/illink/src/linker/Linker.Steps/RootAssemblyInputStep.cs#L13. I suspect you might need a RootMode of |
Hi @dellis1972 or @jonathanpeppers, I suspect this is a bug in Visual Studio since copying the configuration from the project that used the same library is working perfectly: <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<EnableLLVM>True</EnableLLVM>
<AndroidLinkTool>r8</AndroidLinkTool>
<RunAOTCompilation>False</RunAOTCompilation>
</PropertyGroup> However, I cannot find a way to leave it like this in VS using the properties. Any other option breaks the app and causes different errors since the library is partially copied, changed, etc. How can we report this bug? This seems to be a serious problem. |
There are two bugs in Visual Studio:
|
@FANMixco if its definately an issue in VS I'm sure @tondat would advise you to raise an issue using the Report an Issue menu item In visual studio, this way the issue will get routed to the correct team. The VS team use a differnt bug reporting system to this project because it is not an open source project. |
I can understand that VS is not an open-source solution, however, perhaps, @tondat should make us the favor to raise the ticket in such a scenario since they might listen to him. As an almost decade-old Windows Insider and someone who has reported several serious bugs over the years, I have serious doubts, that the dev team will ever consider it even if it impacts the full .NET 8 for Android migrations. Some months ago, I even read a Twit where someone from Microsoft asked about how our status migrating apps and recalled us the VS provided "solution." To be honest, I don't know what I could have replied to that Microsoft employee. The VS solution does not work as expected since it transforms your Xamarin.Android project into a MAUI.NET, not a .NET for Android without a prior warning. Would it work? Maybe, but it's something different. I had to learn on my own how to do it since the documentation was harder to follow and did not work at all in the end. It was easier to add a new project to my solution, copy most of the files, replace If I raised the ticket, I'm sure it would go to a random backlog, waiting for votes that might never get or close since it didn't get too much attention (my own experience) even if in the next update after it was closed, you should raise it again. I sound quite negative, but even recently, I even reported a considerable bug from an enterprise paid Azure account from a large client and have 100% doubts, it will be fixed in the foreseeable future even though the UI and links are broken, blocking any user to use the Azure service. I have no hope, if @tondat would expect that I should raise the "ticket" that anyone from the VS dev team would ever check it. Let's take another example of a similar topic that was fully ignored for years: It was even archived on May 1st, 2024, without a prior warning, documentation, alternatives, or comments. At least there are some new comments in the Android one But would the new version support Android and iOS? Or would it be for Android only? So, what happened to the iOS devs? Who knows, it's unclear. In my opinion, some comments should be added if the iOS project is dead, so people can redirect their efforts properly. In the iOS one, devs were requesting support for some serious bugs, perhaps some documentation of how to use it, the status of the project or to know what to do. Some Microsoft repo users even suggested us to contact @davidortinau, who sadly never replied: I even reached him twice via Twitter/X, but no replies. Perhaps, because I'm not a massive influencer yet. That's why, my hopes are non-existent if it's expected that I should create a new bug request in the VS backlog. I have raised several VS bugs over the years with minimal to no impact that were real bugs some of them even crashed VS. I eventually even stopped raising tickets since many turned on deaf ears. |
They have it documented here: And we even use it here, to preserve unit test cases: Does this not work for you? For your other comments about the IDE, can you file a |
This issue likely occurs in the Visual Studio integration, which is owned by a different team who does not use GitHub for issue tracking. Please use the tools available inside of VS to report this issue. This allows the issue to be routed to the correct team, and provides them the correct logs they need to diagnose it. Thanks! |
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
VS2022
Description
I'm migrating my app from Xamarin.Android to .NET 8 and I'm getting some issues since I don't have an option to exclude some libs that existed in Xamarin:
But in .NET 8 for Android in Visual Studio 2022, there is nothing like that:
I tried to add some code like this one in the
.csproj
:Or like this:
And I got error like these ones:
Without the trimming, my app increases almost twice its size. Any idea how can I exclude this library?
Steps to Reproduce
Did you find any workaround?
No, it used to work in Xamarin.Android.
Relevant log output
The text was updated successfully, but these errors were encountered: