I'm getting these duplicate resources errors.
[color/colorAccent] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\strings.xml [color/colorAccent] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\colors.xml: Error: Duplicate resources
[color/colorPrimary] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\strings.xml [color/colorPrimary] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\colors.xml: Error: Duplicate resources
[color/colorPrimaryDark] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\strings.xml [color/colorPrimaryDark] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\colors.xml: Error: Duplicate resources
[style/AppTheme] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\strings.xml [style/AppTheme] C:\Users\haide\Documents\androidProjects\SkyrimGenerator\SkyrimScenarioCharacterGenerator\app\src\main\res\values\styles.xml: Error: Duplicate resources
Here is my colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
Here is my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and strings.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
This happened after I changed my strings.xml invalidated cache and restarted because it wouldn't update.
I tried multiple permutations of having just one apptheme and one color in a single file, but I get compilation errors. Say I delete apptheme from strings.xml and colors from color.xml, I'll get compilation error. If I have any two duplicates it'll give me duplicate error...
Does anyone know how to fix the error?
I had same issue once... I noticed that i had declared the variable colorPrimary in the app level build.gradle file and also in colors.xml. I fixed the error by removing the resource value in the build.gradle file
I had this in my app level build.gradle
defaultConfig {
...
resValue 'color', "colorPrimary", "#2196F3"
}
And this in my colors.xml
<color name="colorPrimary">#C41426</color>
I removed one of them problem solved
Related
I build a custom aar library with some resouces, included a common and reusable theme in themes.xml.
<style name="Theme.MyThemeLibrary" parent="Theme.Material3.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/clr_primary</item>
<item name="colorPrimaryVariant">#color/clr_primary</item>
<item name="colorOnPrimary">#color/clr_on_primary</item>
...
<style name="Theme.MyThemeLibrary.TextInputLayout" parent="Widget.Material3.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">#color/clr_osc</item>
<item name="startIconTint">#color/clr_tilc</item>
<item name="endIconDrawable">#color/clr_tilc</item>
<item name="android:textColorHint">#color/clr_tilc</item>
<item name="helperTextTextColor">#color/clr_tilc</item>
</style>
<style name="Theme.MyThemeLibrary.Button" parent="Widget.Material3.Button">
<item name="cornerRadius">15dp</item>
</style>
...
I want to use it in another library, so I can't use implementation, but only compileOnly.
compileOnly files('libs/MyThemeLibrary.aar')
I can access correctly to all R resouces like string or color, but not Styles.
Building project give me error in layout files e.g.
AAPT: error: resource style/Style.MyThemeLibrary.Button (aka
com.example.mysecondslibrary:style/Style.MyThemeLibrary.Button) not
found.
Recently I updated my target SDK to 29 as per new Android guidelines but after that I received this error:
D:\Android Apps\PatherPane\app\src\main\res\values\styles.xml:4:5-9:13: AAPT: error: style attribute 'attr/colorPrimary (aka com.patherpane.app:attr/colorPrimary)' not found.
And my style XML file is:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">
#drawable/background_splashscreen
</item>
</style>
How can I fix this?
This command followed by item names is showing the error: Theme.AppCompat.Light.DarkActionBar
Make sure you have not missed appcompat implementation in build.gradle(app)
implementation ‘com.android.support:appcompat-v7:28.0.0’
or
implementation 'androidx.appcompat:appcompat:1.2.0'
if using androidx
This error commonly shows up when
androidx.appcompat:appcompat
and
com.google.android.material:material
versions do not match. Check whether you updated one and not the other
Had this in a library module, which suddenly stopped resolving the theme.
dependencies {
implementation "com.google.android.material:material:1.3.0"
}
Go to app/src/main/res/values/colors.xml
It should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color> //This is where the colorPrimary is defined
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
Make sure that the line that I commented exists, has correct syntax, and defines the appropriate 6-digit hexcode in the middle. The hexcode should be the primary color of the theme you are designing.
I tried to add a background for a theme (ActionBar),
but then everything went wrong.
code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat">
<item name="android:background">"colorPrimary"</item>
</style>
<style name="Theme.AppCompat.DayNight.DarkActionBar" parent="Theme.AppCompat"/>
<style name="Theme.AppCompat.DayNight.Dialog" parent="Theme.AppCompat.Dialog"/>
<style name="Theme.AppCompat.DayNight.Dialog.Alert" parent="Theme.AppCompat.Dialog.Alert"/>
<style name="Theme.AppCompat.DayNight.Dialog.MinWidth" parent="Theme.AppCompat.Dialog.MinWidth"/>
<style name="Theme.AppCompat.DayNight.DialogWhenLarge" parent="Theme.AppCompat.DialogWhenLarge"/>
<style name="Theme.AppCompat.DayNight.NoActionBar" parent="Theme.AppCompat.NoActionBar"/>
</resources>
and I got this message:
Error:(4, 41) String types not allowed (at 'android:background' with value '"colorPrimary"').
decided to revert my code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppCompat.DayNight" parent="Theme.AppCompat"/>
<style name="Theme.AppCompat.DayNight.DarkActionBar" parent="Theme.AppCompat"/>
<style name="Theme.AppCompat.DayNight.Dialog" parent="Theme.AppCompat.Dialog"/>
<style name="Theme.AppCompat.DayNight.Dialog.Alert" parent="Theme.AppCompat.Dialog.Alert"/>
<style name="Theme.AppCompat.DayNight.Dialog.MinWidth" parent="Theme.AppCompat.Dialog.MinWidth"/>
<style name="Theme.AppCompat.DayNight.DialogWhenLarge" parent="Theme.AppCompat.DialogWhenLarge"/>
<style name="Theme.AppCompat.DayNight.NoActionBar" parent="Theme.AppCompat.NoActionBar"/>
</resources>
but then it showed the same error,and the XML file is not really edited.
tried some solutions such as:
1.clean project (didn't work)
2.re-build project (didn't work)
3.delete app/build folder and run AS again (didn't work)
4.run AS as administrator (didn't work)
5.close Android Studio and run again (didn't work)
6.delete only the res folder (didn't work)
everything went wrong.
directory: app\build\intermediates\res\merged\debug\values-night-v8\values-night-v8.xml
Any solutions?
you forgot to add the #color to your background tag :
just change your
<item name="android:background">"colorPrimary"</item>
line with this
<item name="android:background">#color/colorPrimary</item>
and it saying the truth what you have is just a string ,and android has no way to know you meant the colorPrimary value in color resources.
hope this help.
I'm trying to use a custom with Theme.AppCompat.NoActionBar but the IDE throws the error that the named resources cannot be found. Kindly assist.Any help would be greatly appreciated.
The styles.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBar">false</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorPrimaryLight">#color/primary_light</item>
<item name="colorAccent">#color/accent</item>
<item name="textColorPrimary">#color/primary_text</item>
<item name="textColorSecondary">#color/secondary_text</item>
<item name="iconColor">#color/icons</item>
<item name="dividerColor">#color/divider</item>
</style>
</resources>
The colors.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FF9800</color>
<color name="primary_dark">#F57C00</color>
<color name="primary_light">#FFE0B2</color>
<color name="accent">#03A9F4</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#727272</color>
<color name="icons">#212121</color>
<color name="divider">#B6B6B6</color>
</resources>
Just Build > Clean Project Then File > Invalidate Caches / Restart Project.
Rename Your xml Name, Set color.xml instead colors.xml under values folder. Then Build > Clean Project Then Restart Project .
Or try this way
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="green">#00ff00</color>
Reference
Make sure you don't have any imports like mine below
import android.R
This imports the wrong resource.
I was getting the following error which seems to be similar to yours
error: resource color/color_primary (aka com.example.android.test31july:color/color_primary) not found.
I went to colors.xml and created exactly the color resource named "color_primary" and the problem vanished.
Rebuilding can take a long time.
Simply remove the offending line and re-add it.
make sure you use the color tag instead of any other tag.
<color name="name">#123</color>
try this
ContextCompat.getColor(getContext(), R.color.red800)
I have:
in a file build.gradle (dependencies)
dependencies {
compile 'com.android.support:cardview-v7:21.0.+'
}
in a file styles.xml (styles definition)
<resources
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<style name="CardViewStyle">
<item name="android:layout_margin">5dip</item>
<item name="card_view:cardCornerRadius">4dp</item>
<item name="card_view:cardElevation">4dp</item>
</style>
</resources>
But compiler complains:
Error: No resource found that matches the given name: attr 'card_view:cardCornerRadius'.
How do I add some cardView attributes in a style?
Set parent attribute to CardView.
You don't even have to add xmlns:card_view="http://schemas.android.com/apk/res-auto".
Working snippet of code:
<style name="CardViewStyle" parent="CardView">
<item name="cardCornerRadius">4dp</item>
<item name="cardElevation">4dp</item>
</style>
To add to mklimek's answer, you do not even need to add the parent="CardView"
Just avoid the cardView: prefix
So instead of
<item name="cardView:cardElevation">5dp</item>
just use
<item name="cardElevation">5dp</item>
So my complete style code for this is:
<style name="categoriesCardViewButtons">
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="cardCornerRadius">8dp</item>
<item name="cardElevation">5dp</item>
<item name="cardBackgroundColor">#color/grey_ultra_light</item>
<item name="android:paddingBottom">#dimen/l1LayoutPaddingB</item>
</style>
This error can occur if you do not have CardView in your gradle dependencies (in Android Studio) for the module containing your style (even though you have the dependency in the module where you use the card view). In that case, simply add
compile 'com.android.support:cardview-v7:22.2.1'
(or another version) to build.gradle for the module containing themes.xml or styles.xml.
Then, you do not need to set a parent on your style, nor do you need a namespace prefix, but can follow the example in tsik's answer, so all you need is
<style name="myStyle">
<item name="cardCornerRadius">8dp</item>
</style>
This code work well
<style name="MyCardView" parent="CardView">
<item name="cardUseCompatPadding">true</item>
<item name="cardCornerRadius">#dimen/hei_standard_8dp</item>
<item name="cardBackgroundColor">#color/bg_item_list_alphabet</item>
</style>
Note: parent ="CardView"