Android Studio 4.1.1 resource linking failed

Viewed 5162

I created a themes.xml file with this code:

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

However, whenever I try to run this I get the following error:

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.

Please help me fix this,dear Angels Of Stack.

3 Answers

As far as I can tell from the logs, I think you are only defining the colors in the values-night directory and not in values directory. If are providing any configuration specific resources then that resources needs to be defined in the base resource directory.

For example if you define some drawable like splash.xml in drawable-v24 then the drawable splash.xml also needs to be defined in drawable directory.

Let me know if that helps.

In your color.xml which can be found under app>src>main>res>values, you need to add the colors. so, let your xml file look like what is shown below.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#2196F3</color>
    <color name="colorPrimaryLight">#64b5f6</color>
    <color name="colorPrimaryDark">#1976D2</color>
    <color name="colorAccent">#FFFF9800</color>
    <color name="colorTextPrimary">@android:color/white</color>
    <color name="colorScreenBackground">#fff3e0</color>
    <color name="colorTextHint">#E0E0E0</color>
    <color name="purple_500">#6200EE</color>
    <color name="purple_700">#3700B3</color>
    <color name="teal_700">#00796B</color>
    <color name="teal_200">#03DAC5</color>
    <color name="white">#FFFFFF</color>

</resources>

I think you are missing

implementation 'com.google.android.material:material:1.3.0'

Related