0

I have a rather traditional question. In my app I have this line:

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf");

And it returns an exception:

RuntimeException: native typeface cannot be made

What I have:

  • my assets folder is in src/main/ folder of my app;
  • In build.gradle file a wrote the following lines:

    sourceSets { main { assets.srcDirs = ['assets'] } }

  • my filename and extension are in lower case.

I wrote I think all the stackoverflow posts about this problem and tried the following solutions:

  • I wrote context.getAssets() and context.getRessources().getAssets() instead of simply getAssets()
  • I tried to put my font file to fonts dauther older and directly to assets folder
  • I tried to check TTF extension instead of ttf
  • I tried to remove - and _ simbols from the file name

Nothing has helped me. May be you know another solution?

Thank you.

user2957954
  • 1,221
  • 2
  • 18
  • 39

1 Answers1

0

It seems that your assets folder might be misplaced. When using Android Studio the assets folder should be inside of the source sets e.g. src/main/assets/

Also rename the font and remove `-` with `_` and make appropriate changes in the code as well.

UPDATE

I tried to reproduce your issue and found that the issue might be because of an invalid font file. Most probably the downloaded ttf is corrupt. Use this file for fontawsome-webfont

enter image description here

dmSherazi
  • 3,743
  • 5
  • 37
  • 62