简体   繁体   中英

Why am I getting “Android resource linking failed” in my styles.xml file (Android Studio)

Hi I'm working in Android Studio and trying to create a background for my splash screen that uses my 'rideshare_splash' image as the background as in the tutorial I've been following at this timestamp ( https://youtu.be/144TuYxEu2M?t=572 ) but when I go to build I get an error saying 'Android resource linking failed'.

I've looked at similarly titled threads on here but the most relevant ones suggested using attr name instead which didn't work as it was outdated, then I tried the suggestion of having android:colorPrimary but that didn't help either so I thought I'd try asking my own question.

styles.xml Code

<?xml version="1.0" encoding="UTF-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Error message (copy & pasted from build console)

What went wrong:
Execution failed for task ':app:processDebugResources'.
 A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
    Android resource linking failed
     C:\Users\mecha\AndroidStudioProjects\FYP_RideShareApp\app\src\main\res\values\styles.xml:4:5-8:13: AAPT: error: resource color/colorPrimary (aka codebymech.fyprideshareapp:color/colorPrimary) not found.
         
     C:\Users\mecha\AndroidStudioProjects\FYP_RideShareApp\app\src\main\res\values\styles.xml:4:5-8:13: AAPT: error: resource color/colorPrimaryDark (aka codebymech.fyprideshareapp:color/colorPrimaryDark) not found.
         
     C:\Users\mecha\AndroidStudioProjects\FYP_RideShareApp\app\src\main\res\values\styles.xml:4:5-8:13: AAPT: error: resource color/colorAccent (aka codebymech.fyprideshareapp:color/colorAccent) not found.

Extra information

My idea is that there's something wrong with how the tutorial has uses @color/coolorPrimary (as well as colorPrimaryDark and colorAccent) or maybe something about this in the tutorial is outdated as it is a couple months old?

Also a side note: when I opened Android Studio there was no styles.xml only colors, strings and themes.xml files so I had to add my own styles.xml file to follow as the tutorial was doing so maybe that has had an effect?

I think your colors.xml file does not containg these colors(colorPrimary, colorPrimaryDark and colorAccent) You have to define these colors in your color.xml file.

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