This code
<style name="listViewPrefs" parent="#android:Widget.ListView">
...
</style>
produces the following Android Rescources Validation error:
Invalid parent reference: expected #style. There should be no cycles in
resource definitions as this can lead to runtime exceptions.
How can this be fixed?
I think you have to use like,
<style name="listViewPrefs" parent="#android:style/Widget.ListView">
...
</style>
Related
After upgrading from Gradle wrapper 4.4.1 to 6.1.1, along with going from Android build tools 2.3.0 to 4.0.0, builds all of a sudden fail with the following error:
res/values/treeview_styles.xml:3:5-6:13: AAPT: error: invalid resource type 'attr' for parent of style.
The resource file in question looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style parent="#android:attr/listViewStyle" name="treeViewListStyle">
<item name="android:background">#android:color/white</item>
<item name="android:divider">#drawable/divider</item>
</style>
</resources>
What is happening here, and how can I fix this?
Background information: The code comes from a tree list view control I am using in my app. I have simply copied the source tree into mine so that I could make some modifications.
The developer reference for android.R.attr mentions listViewStyle, stating it has been available since API 1, so I am wondering if it is a reference to that. On the other hand, my app uses appcompat-v7, and in my local SDK tree at extras/android/support/v7/appcompat/res/values/themes_base.xml I indeed found:
<style name="Base.Theme.AppCompat.CompactMenu" parent="">
<item name="android:itemTextAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:listViewStyle">#style/Widget.AppCompat.ListView.Menu</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.DropDownUp</item>
</style>
That looks as if android:listViewStyle is just an alias for #style/Widget.AppCompat.ListView.Menu. Indeed, using #style/Widget.AppCompat.ListView.Menu compiles and the UI looks OK at first glance.
Note that the toolchain upgrade included switching from AAPT to AAPT2. According to this question and its answers, AAPT2 is stricter about some things than its predecessor. In particular, parents of styles must be styles as well. That would at least explain the error message, we just need to hunt down the correct resource name.
ianhanniballake wrote:
The problem is parent="#android:attr/listViewStyle", so replacing that with an actual parent theme, and not something from an attribute, would indeed fix it. What theme are you using?
In addition i found that:
Behavior changes when using AAPT2:
Additionally, when declaring a element, its parent must also
be a style resource type. Otherwise, you get an error similar to the
following:
Error: (...) invalid resource type 'attr' for parent of style
I'm receiving the following 2 errors when trying to build my Android project with Gradle:
Error:(598) Attribute "font" already defined with incompatible format.
Error:(2209, 39) String types not allowed (at 'android:typeface' with value 'roboto_medium').
I've looked online elsewhere but can't find the answer to these issues, any clarification or help is much appreciated.
Update:
Here is the stacktrace:
AGPBI: {"kind":"error","text":"Attribute \"font\" already defined with incompatible format.","sources":[{"file":"/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml","position":{"startLine":597}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"Original attribute defined here.","sources":[{"file":"/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml","position":{"startLine":417}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"String types not allowed (at \u0027android:typeface\u0027 with value \u0027roboto_medium\u0027).","sources":[{"file":"/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml","position":{"startLine":2208,"startColumn":38,"startOffset":158093,"endColumn":51,"endOffset":158106}}],"original":"","tool":"AAPT"}
Failed to generate resource table for split ''
/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml:598: error: Attribute "font" already defined with incompatible format.
/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml:418: Original attribute defined here.
/Users/johnbyrne/Documents/myapp-android/MyApp/app/build/intermediates/res/merged/development/debug/values/values.xml:2209: error: Error: String types not allowed (at 'android:typeface' with value 'roboto_medium').
My styles.xml looks like this:
<resources>
<style name="ButtonLight">
<item name="android:typeface">roboto_medium</item>
<item name="android:textSize">#dimen/text_size_button</item>
<item name="android:textColor">#color/black_87</item>
<item name="colorAccent">#color/white</item>
<item name="android:lineSpacingExtra">-2sp</item>
<item name="android:gravity">center_vertical</item>
</style>
</resources>
If you are using Custom fonts in your app then please check once Font or Typeface implemented correctly.
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-black" // roboto black
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)
<style name="ButtonLight">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">#dimen/text_size_button</item>
<item name="android:textColor">#color/black_87</item>
<item name="colorAccent">#color/white</item>
<item name="android:lineSpacingExtra">-2sp</item>
<item name="android:gravity">center_vertical</item>
</style>
Try this.
I have an Xamarin.Forms app that fails to build for Android on my Mac (same on Windows) while it did work fine before (not sure what changed in the meantime). The same projects builds fine on the pc of a colleague.
It's a Xamarin.Forms app using PCL. I get the following errors in my styles.xml file:
Resources/values/styles.xml(3): error APT0000: Error: No resource found that matches the given name: attr 'colorAccent'.
Resources/values/styles.xml(2): error APT0000: Error: No resource found that matches the given name: attr 'colorPrimary'.
Resources/values/styles.xml(2): error APT0000: Error: No resource found that matches the given name: attr 'colorPrimaryDark'.
Resources/values/styles.xml(2): error APT0000: Error: No resource found that matches the given name: attr 'windowActionBar'.
Resources/values/styles.xml(4): error APT0000: Error: No resource found that matches the given name: attr 'windowActionModeOverlay'.
Resources/values/styles.xml(2): error APT0000: Error: No resource found that matches the given name: attr 'windowNoTitle'.
This is what my styles.xml looks like:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme.Splash" parent ="android:Theme.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="android:Theme.Light">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
</style>
</resources>
I can't figure out why it works for on my colleagues pc and not on mine. I've even tried installing ALL Android SDKs and other tools without any success.
I don't know how to continue. Any help is appreciated.
Sorry to trouble i have been trying to fix these issues for the past 2 weeks anything you want to see i can post please help me solve this
I am using Eclipse not android studio here with also my style.xml
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.App">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="title_text_style" parent="android:Widget.TextView">
<item name="android:gravity">center</item>
<item name="android:padding">5dp</item>
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="title_bg">
<item name="android:background">#color/light_green</item>
<item name="android:gravity">center</item>
<item name="android:orientation">vertical</item>
</style>
<style name="editext_register_style" parent="android:Widget.EditText">
<item name="android:background">#drawable/edit_bar_bg_register_big</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:paddingLeft">3dp</item>
<item name="android:textColor">#color/white</item>
<item name="android:textColorHint">#color/white</item>
</style>
<style name="tv_chat_menu_style" parent="android:Widget.Holo.Light.TextView">
<item name="android:gravity">center_horizontal</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textColor">#color/light_green</item>
</style>
<style name="Theme.App" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Theme.App.ActionBar</item>
</style>
<style name="Theme.App.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="displayOptions">showHome|useLogo</item>
</style>
And this below is the errors i am getting when building
Description Resource Path Location Type
error: Error: No resource found that matches the given name: attr 'actionBarStyle'. styles.xml /Shooteka/res/values-v11 line 7 Android AAPT Problem
error: Error: No resource found that matches the given name: attr 'displayOptions'. styles.xml /Shooteka/res/values-v14 line 12 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'. styles.xml /Shooteka/res/values line 48 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Widget.Sherlock.ActionBar'. styles.xml /Shooteka/res/values-v14 line 10 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'. styles.xml /Shooteka/res/values-v11 line 5 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Widget.Sherlock.ActionBar'. styles.xml /Shooteka/res/values line 52 Android AAPT Problem
error: Error: No resource found that matches the given name: attr 'displayOptions'. styles.xml /Shooteka/res/values line 53 Android AAPT Problem
error: Error: No resource found that matches the given name: attr 'actionBarStyle'. styles.xml /Shooteka/res/values line 49 Android AAPT Problem
error: Error: No resource found that matches the given name: attr 'actionBarStyle'. styles.xml /Shooteka/res/values-v14 line 7 Android AAPT Problem
error: Error: No resource found that matches the given name: attr 'displayOptions'. styles.xml /Shooteka/res/values-v11 line 12 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'. styles.xml /Shooteka/res/values-v14 line 5 Android AAPT Problem
error: Error retrieving parent for item: No resource found that matches the given name 'Widget.Sherlock.ActionBar'. styles.xml /Shooteka/res/values-v11 line 10 Android AAPT Problem
Description Resource Path Location Type
The project was not built due to "A resource exists with a different case: '/Shooteka/bin/classes/com/chat'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent Shooteka Unknown Java Problem
I am using actionbar sherlock for compatibility with android version >= 8
and while using the code it gives me error
error: Error: No resource found that matches the given name: attr 'titleTextStyle'.
my code used in the xml is
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.Sherlock.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
You have to change the build SDK to at least API 11 (Honeycomb).
I have experiment this issue too with AndroidSherlock ActionBar. EveryTime I change something inside style I get those erros to. Closing the the style file and clean -> rebuild fix tipically for me