maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android, .NET MAUI 9.0 Preview 5] When building with Visual Studio 17.11.0 Preview 2.1, Maui fails randomly to import the fonts, but still finishes building without errors.

Open janne-hmp opened this issue 1 year ago • 1 comments

Description

Randomly, when building a Maui app with Visual Studio in Windows, the Android version of Maui fails randomly to import the fonts, but still builds apparently fine. Other versions (iOS, Windows) seem to always build fine. This can be especially problematic with release builds going to Google Play Store if the fonts are left out of the package without any errors or warnings.

Steps to Reproduce

Not sure, since it happens very randomly, but still consistently every now and then.

Link to public reproduction project repository

https://github.com/hyvanmielenpelit/GnollHack

Version with bug

9.0.0-preview.4.10690

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

Delete obj and bin directories and hope that the fonts are included next time when building.

Relevant log output

No response

janne-hmp avatar Jun 30 '24 13:06 janne-hmp

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Jun 30 '24 13:06 github-actions[bot]

Possibly related/duplicate #23268

jfversluis avatar Jul 02 '24 13:07 jfversluis

I'm pretty sure this is related to the very unreliably working resizetizer on Android. Fonts are copied (for whatever reason) to obj/Debug/net9.0/resizetizer/f directory and this seems to fail frequently along with many other resizetizer tasks on Android.

The workaround is not to use resizetizer with fonts on Android, but rather copy them to the right location using MauiAsset, as follows:

		<MauiFont Include="Resources\Fonts\*" Condition="'$(TargetFramework)'!='net9.0-android'" />
		<MauiAsset Include="Resources\Fonts\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" Condition="'$(TargetFramework)'=='net9.0-android'" />

janne-hmp avatar Jul 07 '24 16:07 janne-hmp

This is happening in .NET 8.0 now also. It only happens on Debug mode, not Release for me.

Something has changed. This only started in the last few weeks for me.

Deleting bin and obj sometimes works. I have only had it happen ~5 times so I can't pin down what I'm doing if anything to trigger or fix it.

But I am not in .NET 9.0 so it is certainly not a .NET 9.0 only issue.

I am using

<ItemGroup>
	<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.61" />
	<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.61" />
</ItemGroup>

jonmdev avatar Aug 05 '24 07:08 jonmdev

This started happening for me with the latest service release (8.0.90) at the time of writing, but only in Release mode. In Debug mode, fonts are loaded and displayed correctly on Android. It works fine with the previous release, so I had to roll back to an earlier version to create a release build for a client.

In my particular case, it's not random, though, the fonts simply don't get included in the APK, the file is smaller than it should be and thus, the app only shows an "X" where a font icon should be and all other text is displayed with the default system font.

ewerspej avatar Sep 24 '24 09:09 ewerspej

We are seeing the same thing with SR9 @ewerspej and reverting is not a great option for us because it fixes other issues. The workaround above (thanks @janne-hmp!) seems to have worked though if you didn't try it.

reid-kirkpatrick avatar Sep 26 '24 20:09 reid-kirkpatrick

Not sure where MS is with fixing this, but my guess is that this results (along with many other similar issues on Android) from VS 2022 IDE launching design-time build exactly at the same time as when the user selects Rebuild command in VS, which leads to two same build processes running at the same time, causing random sharing violations. If you build the app with dotnet build using command-line tool with Visual Studio closed, fonts are most likely always included correctly. It is also worth noting that if you keep Visual Studio open in the same configuration as where you run dotnet build (e.g., both in Release), then Visual Studio will also start design-time build that causes sharing violations with the dotnet build process, so make sure that Visual Studio is either closed or set in a configuration different to the configuration used in dotnet build (e.g. Debug if dotnet build is Release, or vice versa).

janne-hmp avatar Sep 26 '24 20:09 janne-hmp

We are seeing the same thing with SR9 @ewerspej and reverting is not a great option for us because it fixes other issues. The workaround above (thanks @janne-hmp!) seems to have worked though if you didn't try it.

I'm glad the workaround works for you, I haven't tried that one yet. While workarounds are okay sometimes, this would be the kind that is easily forgotten.

I just reverted to the previous version, which works just fine for me.

ewerspej avatar Sep 26 '24 21:09 ewerspej

The error is still here. Periodically, font files are missing in *.msix assemblies and in unpacked assemblies for Windows Visual Studio Community 2022 v17.11.5


Microsoft.Maui.FontRegistrar: Warning: Unable to load font 'MaterialFont'.

System.IO.FileNotFoundException: Native font with the name materialdesignicons-webfont.ttf was not found.
   at Microsoft.Maui.FontRegistrar.LoadNativeAppFont(String font, String filename, String alias)
   at Microsoft.Maui.FontRegistrar.GetFont(String font)
Microsoft.Maui.FontManager: Error: Error loading font 'Assets/Fonts/MaterialFont.ttf'.

System.InvalidOperationException: This operation is not supported for a relative URI.
   at System.Uri.get_AbsolutePath()
   at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)
Microsoft.Maui.FontManager: Error: Error loading font 'Assets/Fonts/MaterialFont.otf'.

System.InvalidOperationException: This operation is not supported for a relative URI.
   at System.Uri.get_AbsolutePath()
   at Microsoft.Maui.FontManager.FindFontFamilyName(String fontFile)

<ItemGroup>
	<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.61" />
	<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.61" />
</ItemGroup>

alex3696 avatar Oct 14 '24 16:10 alex3696

Actually I'm going to close this one as a duplicate so we won't have issues and info all over the place. I'll look into this soon.

jfversluis avatar Nov 20 '24 10:11 jfversluis

Duplicate of #23268

jfversluis avatar Nov 20 '24 10:11 jfversluis

@janne-hmp The workaround is working for NET 8 too like this:

<MauiAsset Include="Resources\Fonts\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.100" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.100" />

On 8.0.20 fonts were working fine. Now workaround is needed.

VNGames avatar Nov 26 '24 12:11 VNGames