java - Android Studio 4.1.1 资源链接失败
问题描述
我使用以下代码创建了一个 theme.xml 文件:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
但是,每当我尝试运行它时,我都会收到以下错误:
AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{}],"original":"AAPT: C:\\Users\\hagel\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:28: error: resource color/purple_200 (aka com.example.myapplication:color/purple_200) not found.\nC:\\Users\\$name\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:29: error: resource color/purple_700 (aka com.example.myapplication:color/purple_700) not found.\nC:\\Users\\$name\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:30: error: resource color/black (aka com.example.myapplication:color/black) not found.\nC:\\Users\\$name\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:32: error: resource color/teal_200 (aka com.example.myapplication:color/teal_200) not found.\nC:\\Users\\$name\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:33: error: resource color/teal_200 (aka com.example.myapplication:color/teal_200) not found.\nC:\\Users\\$name\\AndroidStudioProjects\\MyApplication\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values-night-v8\\values-night-v8.xml:34: error: resource color/black (aka com.example.myapplication:color/black) not found.\nerror: failed linking references.\n\n ","tool":"AAPT"}
AAPT: C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:28: error: resource color/purple_200 (aka com.example.myapplication:color/purple_200) not found.
C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:29: error: resource color/purple_700 (aka com.example.myapplication:color/purple_700) not found.
C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:30: error: resource color/black (aka com.example.myapplication:color/black) not found.
C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:32: error: resource color/teal_200 (aka com.example.myapplication:color/teal_200) not found.
C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:33: error: resource color/teal_200 (aka com.example.myapplication:color/teal_200) not found.
C:\Users\$name\AndroidStudioProjects\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-night-v8\values-night-v8.xml:34: error: resource color/black (aka com.example.myapplication:color/black) not found.
error: failed linking references.
请帮我解决这个问题,亲爱的堆栈天使。
解决方案
据我从日志中可以看出,我认为您只是在目录中定义颜色,values-night
而不是在values
目录中。如果提供任何特定于配置的资源,则需要在基本资源目录中定义该资源。
例如,如果您splash.xml
在 drawable-v24 中定义了一些可绘制对象,那么该可绘制对象splash.xml
也需要在drawable
目录中定义。
让我知道这是否有帮助。
推荐阅读
- jmeter - 通过 jmeter 没有响应,但通过 POSTMAN 对相同的 REST API 做出正确响应
- plc - 如何使用 OPCAutomation.dll 检查 plc 设备是否断开连接
- java - 无法通过代理调用 API
- rest - 从 Office365 Graph API 中的字符串设置消息
- jquery - 用 jquery 触发按键不起作用
- c# - GC 的 Xamarin 调试输出的含义
- xml - 相对路径在 WIX 和 XML 中不起作用并显示错误“系统找不到文件”
- electron - Theia 的 Electron 示例不运行
- signing - 使用 iText7 签名的 PDF/A 允许在不破坏签名的情况下更改附加文档
- sql - Postgresql - 消除重复条目