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

8

20

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

Hangout answered 11/8, 2017 at 10:56 Comment(22)
What version of Android Studio are you using?Conrado
where is your font family xmlBrittnybritton
I am using 2.3.3 @ConradoHangout
Yes i have read about it.It does not allow me to create the font-family in font folderHangout
@AkhileshPatil It does not provide me option to create the font-family on the font folderHangout
#43153407Alderete
@MikeM. My problem is that i am not able to create the ` Font resource file` when i right click on the font folderHangout
Yeah, you said you're using Android Studio version 2.3.3. You need 2.4, at least.Alderete
It is not updated..I have check on updater..It says u have latest versionHangout
developer.android.com/studio/archive.html, developer.android.com/studio/previewAlderete
Did you find any way to do this?Maladroit
@MohitGoel U need to update your Andoid studio 3. 0 to get this..Currently which android studio version are u using?Hangout
I know that. but I am working on a live project. So I cant take risk of using beta version.Maladroit
Do i need to use old way?Maladroit
Till than YES..It will no harm to u. :)Hangout
I am trying to do the same but it is giving me following error: Error:(417) Attribute "font" already defined with incompatible format.Maladroit
I am also using maven { url 'maven.google.com' }Maladroit
@MohitGoel U need to delete the font folder , if u are using the traditional way..And put the file inside the assest folderHangout
Let us continue this discussion in chat.Maladroit
Sorry i am busy now..Ping u as become freeHangout
Thanks for ur help. its done.Maladroit
@MohitGoel Good to hear dost..Keep happy coding :)Hangout
C
10

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.

Conrado answered 11/8, 2017 at 11:17 Comment(6)
Apparently "canary" has been renamed to "preview" and the Android studio build has been relabeled to "beta": tools.android.com/download/studio/canary/latestVermiculation
Means there is no other way on 2.3.3..I am also using the kotlin whose version 3.0 Beta ..I think it will run on that...But my problem is not resolved because i need to do work on Andorid ..Thanks for input..:)Hangout
@M66B: They must have bumped Android Studio 3.0 up to Beta 1 while I was asleep. Last I knew, they were on Canary 9 or so.Conrado
@RavindraKushwaha: "Means there is no other way on 2.3.3" -- you're welcome to try the 3.0 beta version of the Plugin with AS 2.3.3, but I strongly suspect that it will not work.Conrado
@Conrado it looks more structural, since the "canary" page refers to a "preview" page now. This was changed yesterday (CET) or earlier. Although, on the other hand this page suggests otherwise: developer.android.com/studio/archive.htmlVermiculation
@Conrado Just checked, using the 3.0.0-beta1 version of the Gradle plugin does not work with AS 2.3.3. Gradle sync fails with Error:This Gradle plugin requires Studio 3.0 minimum.Aryan
A
4

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!

Apul answered 31/8, 2017 at 15:27 Comment(3)
Hi there. A number of folks in our community sometimes say that every time they see gendered assumptions about software engineers, they worry about people feeling excluded. I wonder, could you try to avoid adding male-oriented greetings and pronouns in your posts, so as to make for a more welcoming environment? Thank you.P
Indeed, that was my case as well. I wonder why it was duplicated.Despain
In my case, it was a wrongly named values directory. So just scan your structure for a bad name.Venusberg
R
3

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);
Richly answered 17/12, 2017 at 19:21 Comment(1)
Hey!! Look at that. I was already doing what all the other answers were suggesting but it still was not working. This is the only thing that worked for.Cobalt
A
2

I had exactly same error file name must end with .xml I used these settings and problem magically resolved.

Use these setting in Project Level Gradle :

compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
    applicationId "com.company.app"
    minSdkVersion 21
    targetSdkVersion 26
...
}

Use these setting in Application Level Gradle :

classpath 'com.android.tools.build:gradle:3.0.1'

Android Stidio :

Android studio version 3.0.1.

Cheers!

Armada answered 24/1, 2018 at 11:38 Comment(0)
A
2

I had faced same problem!! Just update your build.gradle file to resolve above issue.

classpath 'com.android.tools.build:gradle:3.0.1'

compileSdkVersion 26

buildToolsVersion '26.0.3'

Update your AndroidStudio to latest vetsion.

Enjoy your day.

Ageold answered 5/3, 2018 at 5:44 Comment(0)
B
1

Android Studio 2.4 includes support for all the new developer features available with Android O you need to update studio

And create XML file

1) Right-click the font folder and go to New > Font resource file. The New Resource File window appears.

2) Enter the file name, and then click OK. The new font resource XML opens in the editor.

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
    <font
    android:fontStyle="normal"
    android:fontWeight="400"
    android:font="@font/Montserrat_Regular.otf" />

</font-family>
Brittnybritton answered 11/8, 2017 at 11:1 Comment(3)
I am not able to create Creating a font family on my font folder.It does not provide me option..I know this way..But when i right optiion on font than it does not provide me ` Font resource file`Hangout
I have just checked for update , it does not allow me to update my android studio from 2.3.3 to 2.4..It say u have updated versionHangout
Thanks for input ..Problem is not resolved :(..+1 for effortHangout
E
0

This is kind of generic issue and I faced this one with error message

main\res\lib\poi-3.12-android-a.jar: Error: The file name must end with .xml

I had placed this jar file inside resource folder(res), I removed this jar file and folder it get resolved. Avoid any unwanted files/folder inside res directory.

Elfin answered 5/5, 2020 at 18:13 Comment(0)
T
0

add this code android.disableResourceValidation=true in android/gradle.properties

Terrel answered 7/5 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.