15

I upgraded my project ( Ionic Framework ) from Android to AndroidX. After that, my project started throwing errors while rebuilding. It is giving "AAPT: error: resource color/colorPrimary (aka io.aide.aide:color/colorPrimary) not found." from file "{Project}\android\app\src\main\res\values\styles.xml".

Here is my styles.xml file

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

    <!-- Base application theme. -->
    <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>

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:background">@null</item>
    </style>


    <style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
        <item name="android:background">@drawable/splash</item>
    </style>
</resources>

The folder of styles.xml is as below

enter image description here

In the below post, they suggested to create a color file. Error:(387, 5) error: resource color/colorPrimary (aka com.example.kubix.r3vir3dv3:color/colorPrimary) not found

I am beginner and I do not know what should be in the color file.

Can any one give me any suggestions to overcome this problem?

1
  • can you share colors.xml file? Commented Mar 9, 2020 at 10:02

2 Answers 2

21

In your project, you need to create color.xml file

Right click on values > New > Values Resource File > Enter File Name "color.xml"

Path:

 res/values/color.xml 

This is how your color.xml will look like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">@color/blue_1</color>
    <color name="colorPrimaryDark">@color/blue_1</color>
    <color name="colorAccent">@color/blue_5</color>

    <color name="blue_1">#00101f</color>
    <color name="blue_5">#0078ff</color>

</resources>
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you so much. It solved my problem. Finally, I am able to upgrade my project to AndroidX and build it without errors.
for me, the color.xml had to go straight to /values folder
My file is colors.xml but the hashtable records are <color> ... <color> ,<!-- and can reference other <color> items if they precede-->
I have created the file colors.xml, but didn't put inside values, thank you, it's 2024 and still working perfectly 👍
@swifthing so where did u put it? I have the same problem
3

You need to define the color resources in res/values/colors.xml to avoid the error.

Example :

  • for @color/colorPrimary write the following code in res/values/colors.xml <color name="colorPrimary">#3F51B5</color>

  • for @color/colorPrimaryDark write the following code in res/values/colors.xml <color name="colorPrimaryDark">#303F9F</color>

  • for @color/colorAccent write the following code in res/values/colors.xml <color name="colorAccent">#FF4081</color>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.