简体   繁体   中英

Custom fonts Array not found in Android Studio 3

I'm using Android Studio 3 Stable . Following this

tutorial i was creating a demo instant app . After finishing all the steps it was running in my emulator without any problem. Then i wanted to use custom fonts. I have set custom font for TextView from Layout Editor.

TextView XML:
`

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:fontFamily="@font/dancing_script"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

`
Font XML :

    <font-family xmlns:app="http://schemas.android.com/apk/res-auto"
        app:fontProviderAuthority="com.google.android.gms.fonts"
        app:fontProviderPackage="com.google.android.gms"
        app:fontProviderQuery="Dancing Script"
        app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>


Manifest

 manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstinstantapp.feature">

    <application>
        <activity android:name=".MainActivity">
            <intent-filter android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="myfirstinstantapp.example.com"
                    android:pathPattern="/hello"
                    android:scheme="https" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>


Folder Structure
在此处输入图片说明


But When i try to build i get following error:

 Error:(52) resource array/preloaded_fonts (aka com.example.myfirstinstantapp:array/preloaded_fonts) not found. Error:(52) error: resource array/preloaded_fonts (aka com.example.myfirstinstantapp:array/preloaded_fonts) not found. Error:failed processing manifest. D:\\Android\\AndroidStudioProjects\\MyFirstInstantApp\\base\\build\\intermediates\\manifests\\full\\feature\\debug\\AndroidManifest.xml Error:java.util.co`enter code here`ncurrent.ExecutionException: java.util.concurre`enter code here`nt.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details Error:Execution failed for task ':base:processDebugFeatureResources'. > Failed to execute aapt Information:BUILD FAILED in 2s Information:7 errors 

Am i missing something ?

I am also getting same problem. Create One array file in values and use below code. Refer

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="preloaded_fonts">
        <item>@font/dancing_script </item>
    </array>
</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM