Getting error "file name must end with .xml" while using the "android:fontFamily" of Android O?

Font resources are not fully supported by the Android Studio 2.3.3 build chain. Full support comes with Android Studio 3.0+ and its associated Android Plugin for Gradle version. At that point, you will be able to create a font/ resource directory that goes alongside layout/, menu/, etc.

IOW, hold off on this until you are ready to upgrade to Android Studio 3.0.


I've lost an hour on this error, using AS 3.0 beta2, Gradle 4.x and the correct build-tools.

Turned out I had a copy of the fonts in a folder called "fonts". This folder doesn't show up in the Android project view. And reading the error I didn't catch the 's'. Just a small reminder for you readers!


I just had the same problem and while searching for an answer, I came here on this thread. I've found a solution from deverloper.android.com.

  1. Right click 'res' folder in Android Studio

  2. Choose 'new' > 'Android resource directory'

  3. Name it 'font'

  4. Inhere you should place your font (.ttf) files WITH ONLY a-z 0-9 and _ characters.

  5. Set your font (mine is called 'alegreyaregular.ttf') this way:

Typeface typeface = ResourcesCompat.getFont(this, R.font.alegreyaregular);
TextView textView.setTypeface(typeface);