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] Font Asset Not Found: java.lang.RuntimeException - OpenSansSemibold #17872

Closed
RiyashameedM opened this issue Oct 6, 2023 · 5 comments
Labels
area-fonts Custom fonts and Font related API's platform/android 🤖 t/bug Something isn't working

Comments

@RiyashameedM
Copy link

Description

Encountering a java.lang.RuntimeException: Font Asset 'OpenSansSemibold' Not Found When Registering the Font as an Embedded Resource with the Font File Action Type as Embedded Resource

Code Snippet
MauiProgram.cs
fonts.AddEmbeddedResourceFont(typeof(MauiProgram).Assembly,"OpenSans - Semibold.ttf", "OpenSansSemibold");
Screen Shot
image

Steps to Reproduce

1.Run the attached sample.
2.Open Output Window

Link to public reproduction project repository

https://github.com/RiyashameedM/SimpleSampleFont

Version with bug

7.0.92

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

7.0.92

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

No

Relevant log output

java.lang.RuntimeException: Font asset not found OpenSansSemibold
	at android.graphics.Typeface.createFromAsset(Typeface.java:1044)
	at crc640ec207abc449b2ca.ShellFragmentContainer.n_onCreateView(Native Method)
	at crc640ec207abc449b2ca.ShellFragmentContainer.onCreateView(ShellFragmentContainer.java:41)
	at androidx.fragment.app.Fragment.performCreateView(Fragment.java:3104)
	at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:524)
	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1899)
	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1817)
	at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1729)
	at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:317)
	at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:341)
	at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:276)
	at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:67)
	at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:7867)
	at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:893)
	at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:107)
	at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8902)
	at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8860)
	at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8848)
	at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1645)
	at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
	at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
	at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
	at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4012)
	at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4578)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at androidx.viewpager2.widget.ViewPager2.onLayout(ViewPager2.java:527)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:149)
	at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:43)
	at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:2253)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:953)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891)
	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1638)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1263)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891)
	at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1880)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1640)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891)
	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729)
	at android.widget.LinearLayout.onLayout(LinearLayout.java:1638)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
	at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
	at com.android.internal.policy.DecorView.onLayout(DecorView.java:799)
	at android.view.View.layout(View.java:23693)
	at android.view.ViewGroup.layout(ViewGroup.java:6413)
	at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3999)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3372)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2328)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9087)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
	at android.view.Choreographer.doCallbacks(Choreographer.java:899)
	at android.view.Choreographer.doFrame(Choreographer.java:832)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7872)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
@RiyashameedM RiyashameedM added the t/bug Something isn't working label Oct 6, 2023
@drasticactions
Copy link
Contributor

drasticactions commented Oct 6, 2023

Going by your sample project and your csproj, I believe that error is correct: You didn't embed a font. OpenSans- Semibold.ttf is an included font inside the Resources/Fonts folder and is not embedded. You have no embedded font files in your csproj. So, you're referencing a non-existent file.

スクリーンショット 2023-10-07 0 32 19

If you include an EmbeddedResource of a font, and use the correct file name and font name, it should work.

You may want to refer to the documentation.

@jsuarezruiz jsuarezruiz added the area-fonts Custom fonts and Font related API's label Oct 9, 2023
@RiyashameedM
Copy link
Author

I have verified the sample, and I have set the Build Action for the font file as 'Embedded Resource' and ensured that it is added with the correct file name. However, I am still encountering the problem

@Jacksenss
Copy link

any progress now?

@drasticactions
Copy link
Contributor

any progress now?

As far as I can tell, there's no bug. As I wrote above, OpenSans- Semibold.ttf is not embedded, it's part of theResources/Fonts directory in a default MAUI template app. Trying to access it as an embedded font will cause an exception, since it's not embedded. If you actually embed a font, as the documentation shows and my screenshot shows by updating that provided sample to include a real embedded font, it should work fine. If it's not working for you, you probably didn't configure it correctly.

I would file a new issue if you're having a problem with it, preferably with an example showing what you're trying to do.

@drasticactions drasticactions closed this as not planned Won't fix, can't repro, duplicate, stale Jan 3, 2024
@Jacksenss
Copy link

any progress now?

As far as I can tell, there's no bug. As I wrote above, OpenSans- Semibold.ttf is not embedded, it's part of theResources/Fonts directory in a default MAUI template app. Trying to access it as an embedded font will cause an exception, since it's not embedded. If you actually embed a font, as the documentation shows and my screenshot shows by updating that provided sample to include a real embedded font, it should work fine. If it's not working for you, you probably didn't configure it correctly.

I would file a new issue if you're having a problem with it, preferably with an example showing what you're trying to do.

Thank you,just solved this problem by clear previous data and rebuild .During testing,the font could be found in the apk,but exceptions keep appearing when the code is run.A little strange.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
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 platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants