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

Microsoft.Maui.FontManager: Warning: Unable to load font 'sans-serif-medium' from assets. #13239

Closed
yangbocheng opened this issue Feb 10, 2023 · 19 comments · Fixed by #15759
Closed
Labels
area-fonts Custom fonts and Font related API's fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@yangbocheng
Copy link

Description

There are no changes about fonts of project,
when start debuging a simple program just has added communitytoolkit.mvvm and use class:ObservableObject attr: [ObservableProperty] attr:[RelayCommand]
then font warning is appeared
how to slove it?

> am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.m3/crc64f3d528bca3d24857.MainActivity"
> Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.m3/crc64f3d528bca3d24857.MainActivity }
Resolved pending breakpoint for 'Android.Runtime.JNIEnv.RegisterJniNatives(System.IntPtr, System.Int32, System.IntPtr, System.IntPtr, System.Int32)' to /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.cs:127 [0x00000].
Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointSendToIde(System.String)' to D:\a\_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:423 [0x00000].
Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointCheckpoint()' to D:\a\_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:418 [0x00000].
[.companyname.m] Late-enabling -Xcheck:jni
[.companyname.m] Unquickening 12 vdex files!
[.companyname.m] Unexpected CPU variant for X86 using defaults: x86_64
[.companyname.m] The ClassLoaderContext is a special shared library.
[NetworkSecurityConfig] No Network Security Config specified, using platform default
[NetworkSecurityConfig] No Network Security Config specified, using platform default
[debug-app-helper] Checking if libmonodroid was unpacked to /data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64/libmonodroid.so
[debug-app-helper] Native libs extracted to /data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64, assuming application/android:extractNativeLibs == true
[debug-app-helper] Setting up for DSO lookup in app data directories
[debug-app-helper] Added filesystem DSO lookup location: http://222.178.203.72:19005/whst/63/=fhsgtazbnl//data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64
[debug-app-helper] Using runtime path: /data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64
[debug-app-helper] checking directory: `/data/user/0/com.companyname.m3/files/.__override__/lib`
[debug-app-helper] directory does not exist: `/data/user/0/com.companyname.m3/files/.__override__/lib`
[debug-app-helper] Checking whether Mono runtime exists at: /data/user/0/com.companyname.m3/files/.__override__/libmonosgen-2.0.so
[debug-app-helper] Checking whether Mono runtime exists at: /data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64/libmonosgen-2.0.so
[debug-app-helper] Mono runtime found at: /data/app/~~VJPZXjgXgUpvzaIZui6sJA==/com.companyname.m3-hjElyQLeTMNL9_qRI5s9Iw==/lib/x86_64/libmonosgen-2.0.so
[.companyname.m] Attempt to remove non-JNI local reference, dumping thread
[DOTNET] JNI_OnLoad: JNI_OnLoad in pal_jni.c
[monodroid] Creating public update directory: `/data/user/0/com.companyname.m3/files/.__override__`
[.companyname.m] Attempt to remove non-JNI local reference, dumping thread
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=10.0.2.2:50923,embedding=1
[monodroid-assembly] open_from_bundles: failed to load assembly m3.dll
[monodroid-gc] GREF GC Threshold: 46080
[monodroid-assembly] open_from_bundles: failed to load assembly Mono.Android.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Java.Interop.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.InteropServices.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Collections.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Threading.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Threading.Thread.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Diagnostics.StackTrace.dll
[.companyname.m] Attempt to remove non-JNI local reference, dumping thread
[monodroid-assembly] open_from_bundles: failed to load assembly netstandard.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Linq.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.HotReload.Contracts.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.HotReload.Contracts.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Collections.Concurrent.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Text.Json.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Text.Encodings.Web.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.ComponentModel.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Controls.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.HotReload.Contracts.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.HotReload.Contracts.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.ObjectModel.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Graphics.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Essentials.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Logging.Abstractions.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.ComponentModel.TypeConverter.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Private.Uri.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Loader.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Memory.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Emit.Lightweight.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Emit.ILGeneration.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Primitives.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Core.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.DependencyInjection.Abstractions.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Console.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Controls.Xaml.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Configuration.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Configuration.Abstractions.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Logging.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Logging.Debug.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.AppCompat.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.Google.Android.Material.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.SwipeRefreshLayout.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Fragment.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Activity.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Lifecycle.ViewModel.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Lifecycle.Common.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.SavedState.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.DrawerLayout.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.CustomView.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Navigation.Runtime.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Net.Primitives.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Options.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.DependencyInjection.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Diagnostics.Tracing.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Xml.ReaderWriter.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Private.Xml.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Text.Encoding.Extensions.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Numerics.Vectors.dll
[.companyname.m] Explicit concurrent copying GC freed 28343(1792KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 1924KB/2565KB, paused 585us total 3.900ms
[monodroid-assembly] open_from_bundles: failed to load assembly System.Text.RegularExpressions.dll
Thread started:  #2
Thread started:  #3
Thread started:  #4
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Serialization.Json.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Private.DataContractSerialization.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Serialization.Xml.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Serialization.Primitives.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.RecyclerView.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.CardView.dll
[libEGL] loaded /vendor/lib64/egl/libEGL_emulation.so
[libEGL] loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
[libEGL] loaded /vendor/lib64/egl/libGLESv2_emulation.so
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Loader.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Controls.Compatibility.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Window.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.CoordinatorLayout.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Lifecycle.LiveData.Core.dll
[.companyname.m] Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
[.companyname.m] Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.ViewPager2.dll
[TabLayout] MODE_SCROLLABLE + GRAVITY_FILL is not supported, GRAVITY_START will be used instead
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Lifecycle.Runtime.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.ViewPager.dll
[monodroid-assembly] open_from_bundles: failed to load assembly CommunityToolkit.Mvvm.dll
[.companyname.m] Explicit concurrent copying GC freed 511(50KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 2975KB/3967KB, paused 334us total 4.521ms
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.AppCompat.AppCompatResources.dll
Thread started: .NET Timer #5
[HostConnection] HostConnection::get() New Host Connection established 0x75558c984190, tid 12537
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
[OpenGLRenderer] Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
[EGL_emulation] eglCreateContext: 0x75557c9bb450: maj 3 min 0 rcv 3
[EGL_emulation] eglMakeCurrent: 0x75557c9bb450: ver 3 0 (tinfo 0x75551d32a860) (first time)
[Gralloc4] mapper 4.x is not supported
[HostConnection] createUnique: call
[HostConnection] HostConnection::get() New Host Connection established 0x75558c986410, tid 12537
[goldfish-address-space] allocate: Ask for block of size 0x100
[goldfish-address-space] allocate: ioctl allocate returned offset 0x3f3ffe000 size 0x2000
[HostConnection] HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Emoji2.dll
[monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Primitives.dll
[0:] Microsoft.Maui.FontManager: Warning: Unable to load font 'sans-serif-medium' from assets.

Java.Lang.RuntimeException: Font asset not found sans-serif-medium
   at Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 12890
   at Java.Interop.JniPeerMembers.JniStaticMethods.InvokeObjectMethod(String encodedMember, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:line 151
   at Android.Graphics.Typeface.CreateFromAsset(AssetManager mgr, String path) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Graphics.Typeface.cs:line 613
   at Microsoft.Maui.FontManager.LoadTypefaceFromAsset(String fontfamily, Boolean warning) in D:\a\_work\1\s\src\Core\src\Fonts\FontManager.Android.cs:line 122
  --- End of managed Java.Lang.RuntimeException stack trace ---

Steps to Reproduce

above all

Link to public reproduction project repository

above all

Version with bug

7.0 (current)

Last version that worked well

7.0 (current)

Affected platforms

Android

Affected platform versions

Pixel 5 - API 30 Android 11.0

Did you find any workaround?

No response

Relevant log output

No response

@yangbocheng yangbocheng added the t/bug Something isn't working label Feb 10, 2023
@jsuarezruiz jsuarezruiz added the area-fonts Custom fonts and Font related API's label Feb 10, 2023
@jfversluis jfversluis added the s/needs-repro Attach a solution or code which reproduces the issue label Feb 13, 2023
@ghost
Copy link

ghost commented Feb 13, 2023

Hi @yangbocheng. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@yangbocheng
Copy link
Author

repos
https://github.com/yangbocheng/formauifont.git

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Feb 13, 2023
@jsuarezruiz jsuarezruiz removed the s/needs-attention Issue has more information and needs another look label Feb 13, 2023
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Feb 13, 2023
@ghost
Copy link

ghost commented Feb 13, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jfversluis
Copy link
Member

So I see that you have both CommunityToolkit.Maui and CommunityToolkit.Mvvm. I definitely have seen this error also in our .NET MAUI Community Toolkit sample app.

Would you mind try:

  • Uninstall the MVVM package and see if the error is still there
  • Install the MVVM package and remove the .NET MAUI package and see if the error is still there

Just trying to see which one of these is the culprit, although it almost has to be the .NET MAUI Toolkit I think...

Thanks!

@jfversluis jfversluis added the s/needs-info Issue needs more info from the author label Feb 13, 2023
@ghost
Copy link

ghost commented Feb 13, 2023

Hi @yangbocheng. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@brminnick
Copy link
Contributor

brminnick commented Feb 13, 2023

EDIT: Never mind, the error still occurs at runtime on Android despite the below fix. The below fix does fix the compiler error at build time, though.

Looking at your reproduction sample, you need to fix a typo in MauiProgram.CreateMauiApp().

You need to include the file extension when using .AddFont() in .ConfigureFonts().

Current (Bug)

fonts.AddFont("Font Awesome 6 Free-Solid-900", "f6"); // Missing `.otf` file extension

Fixed

fonts.AddFont("Font Awesome 6 Free-Solid-900.otf", "f6"); // Includes `.otf` file extension

MauiProgram.CreateMauiApp()

public static MauiApp CreateMauiApp()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()
		.UseMauiCommunityToolkit()
		.ConfigureFonts(fonts =>
		{
			fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
			fonts.AddFont("Font Awesome 6 Free-Solid-900.otf", "f6"); // Includes `.otf` file extension
		});

	registerViewAndVM(builder.Services);
	RegisterEssentials(builder.Services);

#if DEBUG
    builder.Logging.AddDebug();
#endif

	var z = builder.Build();
	ServiceLocater.Init(z.Services);
	return z;
}

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Feb 13, 2023
@yangbocheng
Copy link
Author

yangbocheng commented Feb 14, 2023

hello, i have updated this repo
https://github.com/yangbocheng/formauifont
which has remove all packages about CommunityToolkit and append the font name with '.otf'

but this font error java.lang.RuntimeException: Font asset not found sans-serif-medium still occurs In Android

	<ItemGroup>
		<!--<PackageReference Include="CommunityToolkit.Maui" Version="4.0.0" />-->
		<!--<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />-->
		<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
		<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
	</ItemGroup>

@Adrian-Ionita
Copy link

Adrian-Ionita commented Feb 14, 2023

Change the file name:
"OpenSans-Semibold.ttf" to "opensans_semibold.ttf" (android style).
Then, in MauiApp CreateMauiApp:
fonts.AddFont("opensans_semibold.ttf", "OpenSansSemibold");

@yangbocheng
Copy link
Author

Change the file name: "OpenSans-Semibold.ttf" to "opensans_semibold.ttf" (android style). Then, in MauiApp CreateMauiApp: fonts.AddFont("opensans_semibold.ttf", "OpenSansSemibold");

i have changed the font file name as what has suggested, but the problem just stay the same

here is updated git example
https://github.com/yangbocheng/formauifont

@Adrian-Ionita
Copy link

Adrian-Ionita commented Feb 15, 2023

Try to include font extension ".ttf".
From:

.ConfigureFonts(fonts =>
			{
				fonts.AddFont("opensan_regular", "OpenSansRegular");
				fonts.AddFont("opensan_semibold", "OpenSansSemibold");
				fonts.AddFont("f6fs9.otf", "f6");
			});

To:

.ConfigureFonts(fonts =>
			{
				fonts.AddFont("opensan_regular.ttf", "OpenSansRegular");
				fonts.AddFont("opensan_semibold.ttf", "OpenSansSemibold");
				fonts.AddFont("f6fs9.otf", "f6");
			});	

@yangbocheng
Copy link
Author

i have added in repos

@JoacimWall
Copy link

Hi have a similar error when porting a Xamarin.forms app to MAUI and test in iOS.
Looks like MAUI is case sensitive for the font filename. This was not the case in Xamarin.Forms.

//Joacim

@MDale-RAC
Copy link

MDale-RAC commented May 8, 2023

I was encountering this error, which had the added issue that I was then unable to hit breakpoints that I placed in my code for debugging in Visual Studio. The app would continue to run, but it was no longer possible to check on the state of the application to debug after the error was thrown!


Workaround:

  1. Download Open Sans Medium 500 Font from Google Fonts (Google Fonts - Open Sans)

  2. Unzip the downloaded .zip (For me: Open_Sans.zip), navigate to the unzipped folder, and copy static/OpenSans-Medium.ttf

  3. Paste the ttf file in your project under Resources/Fonts/

  4. In your MauiProgram.cs file, add the font:

[...]

public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				// Default fonts
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
				fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
				// Font added to address issue: https://github.com/dotnet/maui/issues/13239
				// fonts.AddFont("OpenSans-Medium.ttf", "OpenSansMedium"); !! Still throws error !!
				// Alias set to match error string
				fonts.AddFont("OpenSans-Medium.ttf", "sans-serif-medium");
			});
		[...]
	}
}

For me, on the Android Emulator, the error was no longer thrown after adding this font with the sans-serif-medium alias.


With the error no longer being thrown, I could hit my breakpoints again without issue!

@mstefarov
Copy link

I ran into the same error in my MAUI app, when running on an older Android device (OnePlus 3T running OxygenOS 9). It seems this phone does not have a built-in font with the name sans-serif-medium. The workaround suggested above (adding OpenSans-Medium.ttf aliased to sans-serif-medium) has solved the problem for me.

@gktval
Copy link

gktval commented May 16, 2023

I am just now recently getting a similar error when debugging to android device. This had been working fine on previous versions on the same phone. Started happening on version 7.0.86. OpenSans-Semibold.tff is in the Fonts folder and the property <MauiFont Include="Resources\Fonts\*" /> is included in the csproj.

Update: seems like it was case sensitive. Changing:
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
to
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemiBold");
fixed it.

image

@MDale-RAC
Copy link

Update: seems like it was case sensitive. Changing:
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
to
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemiBold");
fixed it.

For me, neither OpenSansSemibold nor OpenSansSemiBold fixed the error (or the inability to then hit breakpoints), but I had only version 7.0.81 (on an emulator, Pixel 5, default options, Android 13.0/API 33).

After updating to version 7.0.86 (and just using the default fonts), I still encountered the same error:

java.lang.RuntimeException: Font asset not found sans-serif-medium

BUT(!), I no longer had the breakpoint issue (I can now hit breakpoints even after encountering the error; I am not even sure if these were actually related issues to begin with)

I still need the alias to match the error string to resolve the error (as mentioned in my comment above):

fonts.AddFont("OpenSans-Medium.ttf", "sans-serif-medium");

FYI

@hypdeb
Copy link

hypdeb commented Jul 2, 2023

I don't know if it's related, but I'm noticing right now that when built in Debug, fonts are working as expected, but when building in Release, they are not. I'm using the latest preview version.

@jfversluis
Copy link
Member

From what I can tell this is fixed by #15759, please try again when that is released. If you still see any weird behavior then, feel free to open a new issue. Thanks!

@samhouts samhouts modified the milestones: Backlog, .NET 8 Planning, .NET 8 Jul 10, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! label Jul 11, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-fonts Custom fonts and Font related API's fixed-in-8.0.0-preview.6.8686 Look for this fix in 8.0.0-preview.6.8686! platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet