Skip to content
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

[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. #23364

Open
janne-hmp opened this issue Jun 30, 2024 · 9 comments
Labels
area-fonts Custom fonts and Font related API's platform/android 🤖 t/bug Something isn't working

Comments

@janne-hmp
Copy link

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 janne-hmp added the t/bug Something isn't working label Jun 30, 2024
Copy link
Contributor

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.

@jfversluis
Copy link
Member

Possibly related/duplicate #23268

@janne-hmp
Copy link
Author

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'" />

@jonmdev
Copy link

jonmdev commented Aug 5, 2024

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>

@samhouts samhouts added the area-fonts Custom fonts and Font related API's label Aug 29, 2024
@ewerspej
Copy link

ewerspej commented Sep 24, 2024

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.

@reid-kirkpatrick
Copy link

reid-kirkpatrick commented Sep 26, 2024

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.

@janne-hmp
Copy link
Author

janne-hmp commented Sep 26, 2024

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).

@ewerspej
Copy link

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.

@alex3696
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-fonts Custom fonts and Font related API's platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants