Android O give font directory with new android-studio version 3.0 but when in drop font-file in font directory and run project it give me a error in font file in font directory. Error:Execution failed for task ':app:mergeDebugResources'.
/home/ttuser4/Downloads/fontPractice/app/src/main/res/font/Dancing_Script.ttf: Error: The file name must end with .xml
I also got the similar issue. To fix that i followed the below steps.
distributionUrl
inproject-dir/gradle/gradle-wrapper.properties
to latest gradle distribution url(You can get the latest availability of gradle from here) to update the gradle version used to build like below.com.android.tools.build:gradle
version in the rootbuild.gradle
to the latest like below. (Note: Below mentioned version is the latest one when the answer is posted. The version might be change in future. So take care about that.)It worked for me. Let me know with your comments.
You can add font in any format, but you have to create a
Font Family
xml file in order to apply these fonts in xml layout file. A font family is an XML file that contains multiple font files along with its style and weight details. You can access the font family as a single unit.To create a font family, perform the following steps in the Android Studio:
Right-click the font folder and go to New > Font resource file. The New Resource File window appears.
Enter the file name, and then click OK. The new font resource XML opens in the editor.
Enclose each font file, style, and weight attribute in the element. The following XML illustrates adding font-related attributes in the font resource XML:
Then you can add this font-family to any element in layout containing text. Like in this example its applying to
TextView
,Suppose you have opened your Android Studio Project.
Right click on
res
directory, and selectNew > Android Resource Directory
.Select resource directory "font".
When I changed it to
pacifico.ttf
, it worked.I've followed the exact same steps on the Android Studio 3.0 Preview with "pacifico.ttf" font, and it works for me.
In case you encounter any errors, clean project once and then run it again.
Do let me know if you still run into issues.
I am assuming you are using an older build tools plugin, so it does not know about res/font and the new font capabilities.
I had the same problem I update to gradle build tools 2.4.0-alpha7
but I got an error message on build and then had to set environment variable