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

Ravindra Kushwaha picture Ravindra Kushwaha · Aug 11, 2017 · Viewed 34k times · Source

Android O introduces a new feature, Fonts in XML, which lets you use fonts as resources. And I am creating the font folder in resource file as it provided by Android developer, but the problem is that I am getting error that file name must end with .xml while using the font folder which is provided in Android O release.

Please check the below layout for it.

 <TextView
   android:id="@+id/txtMsgCount"
   android:layout_width="wrap_content"
   android:layout_height="16dp"
   android:background="@drawable/msg_count"
   android:gravity="center"
   android:text="123"
   android:fontFamily="@font/Montserrat_Regular" ////IT IS MY FONT STYLE
   android:textColor="@android:color/white"
   android:textSize="10sp" />

And please check the font folder which I have created in res with Montserrat_Regular.otf file

My font folder with font style

I am getting the following error while using the above, which are as follows:

Error getting

I have searched about it but did not get expected result, please check:

1. First Link
2. Second Link
3. Third Link
4. Forth Link

And the Font resource file is not creating as I am clicking the Right-click the font folder and go to New > Font resource file. But not getting the option of the Font resource file, please check below:

enter image description here

Answer

CommonsWare picture CommonsWare · Aug 11, 2017

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.