# Why can't I read .ttf file when running Android configuration?

When running or debugging my game on Android device, I get this error in the logcat:

Which is created by this code line:

FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);


where fontFile is defined like this:

FileHandle fontFile = Gdx.files.internal("data/fonts/myFont.ttf");


This doesn't happen when I run the desktop configuration.

I know that for desktop configuration you have to define the working directory of your project, but I don't see such option in android configuration and it also makes no sense, so I don't think it's a "working directory"-related problem.

Obviously, the file is in the correct path.

Also note that everything worked fine in my previous project. I created this new project by creating a new blank prj using libgdx-setup and then copying all the classes and packages from the older project. So maybe it's a problem related to some Gradle file?

• are you getting a FileNotFoundException? Android file-system is case sensitive, make sure that you wrote it correctly "myFont.ttf" is different that "myFont.TTF" – Alex Sifuentes Jul 6 '15 at 13:36
• Yes, i didn't read it in the logcat, here is the other part of the logcat message: Caused by: java.io.FileNotFoundException: data/fonts/myFont.ttf at android.content.res.AssetManager.openAsset(Native Method) at android.content.res.AssetManager.open(AssetManager.java:359) at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75) I'm sure file is correct, it's inside assets/data/fonts/myFont.ttf I think for some reason Android is not looking in the correct folder... But running the desktop configuration works fine – Davide Cattani Jul 6 '15 at 17:53

I believe for android you need to have an assets folder with all of the assets loaded into it, this assets folder would be in the android project rather than the core project. Desktop, HTML, etc all use core project assets so they would work fine, but android needs its own assets folder. do you have one for it?

• Desktop HTML and core use Android assets folder, which is the only assets folder in the project. – Davide Cattani Jul 12 '15 at 10:46

The Options are:

1) Try TTF upper case instead of ttf in all of your code - in case your original file has TTF suffix, because android is case sensitive.

assets.srcDirs = ['assets']


And not:

assets.srcDirs = ['assetManager']


In another words make sure its your android assets folder. this one worked for me. then clean build project, and uninstall old app from android device.

• [DMGregory] got it, answer edited. – Yan.F May 31 '17 at 19:58

Try copying the font files directly into the assets folder.

Just do one thing you can change the method which your following now. you can use the "hiero" tool for the font creation . Just download "hiero" jar file from the following link

by using hiero you will be able to access almost all the fonts . after creating the fonts save it on your android project files "asset" folder and add the folowing code.

     private BitmapFont font;
font = new BitmapFont(Gdx.files.internal("myNewFontCreatedByHiero.fnt"));


just try this method. it will work.

• Sorry, have to downvote this. Using the FreeTypeFontGenerator let's you import any font and write with it in any size. Where Hiero requires you to generate bitmaps for each font and size. I agree that hiero is a great tool but this is not answering the question. – Madmenyo Jan 19 '17 at 6:36
• @Madmenyo Hi, I just give a alternate way to solve his problem. The above concept is not wrong. Which is the alternate solution to his problem. I don't know what is the exact reason for down vote. – Gokul Sreenivasan Jan 19 '17 at 7:22
• How do you know? Maybe he needs a lot of dynamically generated text, hiero does not help with that. – Madmenyo Jan 19 '17 at 7:39
• @Madmenyo Hi , you may read his question first. I have given an alternat solution. – Gokul Sreenivasan Jan 19 '17 at 7:41
• He wants to load ttf you suggest creating a bitmap font. – Madmenyo Jan 19 '17 at 7:43

Make sure the files are inside /android/assets.