简体   繁体   English

为什么我的 styles.xml 文件 (Android Studio) 中出现“Android 资源链接失败”

[英]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'.嗨,我在 Android Studio 工作,并尝试为我的启动画面创建一个背景,该背景使用我的“rideshare_splash”图像作为背景,正如我在这个时间戳上一直在关注的教程中一样( https://youtu.be/144TuYxEu2M ?t=572 )但是当我 go 构建时,我收到一条错误消息,提示“Android 资源链接失败”。

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.我在这里查看了类似标题的线程,但最相关的线程建议使用attr 名称而不是因为它已经过时而不起作用,然后我尝试了使用android:colorPrimary的建议,但这也没有帮助所以我想我会尝试问我自己的问题。

styles.xml Code styles.xml代码

<?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?我的想法是本教程使用@color/coolorPrimary(以及colorPrimaryDark和colorAccent)的方式有问题,或者本教程中的某些内容可能已经过时了,因为它已经有几个月的历史了?

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? 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. 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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