How to exclude some libraries to be trimmed in .NET 8 for Android, not MAUI?
I've been 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
:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>link</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>
<ItemGroup>
<TrimmerRootAssembly Include="Xamarin-MaterialSearchBar" RootMode="CopyUsed" />
</ItemGroup>
Or like this:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<EnableLLVM>True</EnableLLVM>
<JavaMaximumHeapSize>2G</JavaMaximumHeapSize>
<AndroidKeyStore>False</AndroidKeyStore>
<TrimMode>link</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" />
</ItemGroup>
And I got error like these ones:
Severity Code Description Project File Line Suppression State
Error MSB4096 The item "Xamarin-MaterialSearchBar" in item list "TrimmerRootAssembly" does not define a value for metadata "RootMode"
Severity Code Description Project File Line Suppression State
Error IL1037 Invalid assembly root mode 'CopyUsed'.
Severity Code Description Project File Line Suppression State
Error NETSDK1144 Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.
Without the trimming, my app increases almost twice its size. Any idea how can I exclude this library?