54

Ok, so im a beginner in android development and I just created the hello world app. But it's giving me errors in styles_base.xml file of appcompat_v7 library.

error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'. styles_base.xml /appcompat_v7/res/values-v21
AAPT Problem

How do i take care of this error? Also why is the appcompat_v7 library being used when I don't want it? I mean how do I create the hello world app without using the appcompat_v7 library?

This is the styles_base.xml file which is giving the above error.

<resources>

<!-- Like in themes_base.xml, the namespace "*.AppCompat.Base" is used to
 define base styles for the platform version. The "*.AppCompat"
 variants are for direct use or use as parent styles by the app. -->
<eat-comment/>

<style name="Base.Widget.AppCompat.ActionBar.TabView"
       parent="android:Widget.Material.ActionBar.TabView">
</style>

<style name="Base.Widget.AppCompat.Light.ActionBar.TabView"
       parent="android:Widget.Material.Light.ActionBar.TabView">
</style>

<style name="Base.Widget.AppCompat.ActionBar.TabText"
       parent="android:Widget.Material.ActionBar.TabText">
</style>

<style name="Base.Widget.AppCompat.Light.ActionBar.TabText"
       parent="android:Widget.Material.Light.ActionBar.TabText">
</style>

<style name="Base.Widget.AppCompat.Light.ActionBar.TabText.Inverse"
       parent="android:Widget.Material.Light.ActionBar.TabText">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Menu"
       parent="android:TextAppearance.Material.Widget.ActionBar.Menu">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
       parent="android:TextAppearance.Material.Widget.ActionBar.Title">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
       parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
       parent="android:TextAppearance.Material.Widget.ActionBar.Title.Inverse">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse"
       parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle.Inverse">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionMode.Title"
       parent="android:TextAppearance.Material.Widget.ActionMode.Title">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.ActionMode.Subtitle"
       parent="android:TextAppearance.Material.Widget.ActionMode.Subtitle">
</style>

<!-- Action Button Styles -->

<style name="Base.Widget.AppCompat.ActionButton"
       parent="android:Widget.Material.ActionButton">
</style>

<style name="Base.Widget.AppCompat.ActionButton.CloseMode"
       parent="android:Widget.Material.ActionButton.CloseMode">
</style>

<style name="Base.Widget.AppCompat.ActionButton.Overflow"
       parent="android:Widget.Material.ActionButton.Overflow">
</style>

<!--
    Widget.AppCompat.Toolbar style is purposely ommitted. This is because the support
    Toolbar implementation is used on ALL platforms and relies on the unbundled attrs.
    The supporting Toolbar styles below only use basic attrs so work fine.
-->

<style name="Base.Widget.AppCompat.Toolbar.Button.Navigation"
       parent="android:Widget.Material.Toolbar.Button.Navigation">
</style>

<style name="Base.TextAppearance.Widget.AppCompat.Toolbar.Title"
       parent="android:TextAppearance.Material.Widget.ActionBar.Title">
</style>

<style name="Base.TextAppearance.Widget.AppCompat.Toolbar.Subtitle"
       parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle">
</style>

<!-- Spinner Widgets -->

<style name="Base.Widget.AppCompat.ListView.DropDown"
       parent="android:Widget.Material.ListView.DropDown"/>

<style name="Base.Widget.AppCompat.DropDownItem.Spinner"
       parent="android:Widget.Material.DropDownItem.Spinner"/>

<style name="Base.Widget.AppCompat.Spinner" parent="android:Widget.Material.Spinner" />

<style name="Base.Widget.AppCompat.Spinner.DropDown.ActionBar" parent="android:Widget.Material.Spinner">
    <item name="spinnerMode">dropdown</item>
    <item name="disableChildrenWhenDisabled">true</item>
    <item name="popupPromptView">@layout/abc_simple_dropdown_hint</item>
</style>

<style name="Base.Widget.AppCompat.ListView.Menu"
       parent="android:Widget.Material.ListView" />

<!-- Popup Menu -->

<style name="Base.Widget.AppCompat.ListPopupWindow" parent="android:Widget.Material.ListPopupWindow">
</style>

<style name="Base.Widget.AppCompat.PopupMenu" parent="android:Widget.Material.PopupMenu">
</style>

<style name="Base.Widget.AppCompat.Light.PopupMenu"
    parent="android:Widget.Material.Light.PopupMenu">
</style>

<style name="Base.Widget.AppCompat.PopupMenu.Overflow">
    <item name="android:dropDownHorizontalOffset">-4dip</item>
    <item name="android:overlapAnchor">true</item>
</style>

<style name="Base.Widget.AppCompat.Light.PopupMenu.Overflow">
    <item name="android:dropDownHorizontalOffset">-4dip</item>
    <item name="android:overlapAnchor">true</item>
</style>

<style name="Base.TextAppearance.AppCompat.Widget.PopupMenu.Large"
    parent="android:TextAppearance.Material.Widget.PopupMenu.Large">
</style>

<style name="Base.TextAppearance.AppCompat.Widget.PopupMenu.Small"
    parent="android:TextAppearance.Material.Widget.PopupMenu.Small">
</style>

<style name="Base.TextAppearance.AppCompat.Light.Widget.PopupMenu.Large"
    parent="android:TextAppearance.Material.Widget.PopupMenu.Large">
</style>

<style name="Base.TextAppearance.AppCompat.Light.Widget.PopupMenu.Small"
    parent="android:TextAppearance.Material.Widget.PopupMenu.Small">
</style>

<!-- Search View result styles -->

<style name="Base.TextAppearance.AppCompat.SearchResult.Title"
       parent="@android:TextAppearance.Material.SearchResult.Title">
</style>

<style name="Base.TextAppearance.AppCompat.SearchResult.Subtitle"
       parent="@android:TextAppearance.Material.SearchResult.Subtitle">
</style>

<style name="Base.Widget.AppCompat.AutoCompleteTextView" parent="android:Widget.Material.AutoCompleteTextView" />

<style name="Base.Widget.AppCompat.Light.AutoCompleteTextView" parent="android:Widget.Material.AutoCompleteTextView" />

<!-- Progress Bar -->

<style name="Base.Widget.AppCompat.ProgressBar.Horizontal"
       parent="android:Widget.Material.ProgressBar.Horizontal">
</style>

<style name="Base.Widget.AppCompat.ProgressBar"
       parent="android:Widget.Material.ProgressBar">
</style>

<!-- TODO. Needs updating for Material -->
<style name="Base.Widget.AppCompat.ActivityChooserView" parent="">
    <item name="android:gravity">center</item>
    <item name="android:background">@drawable/abc_ab_share_pack_holo_dark</item>
    <item name="android:divider">?attr/dividerVertical</item>
    <item name="android:showDividers">middle</item>
    <item name="android:dividerPadding">6dip</item>
</style>


This is the code I'm using:

public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
   }
}
reVerse
  • 35,075
  • 22
  • 89
  • 84
divinesense
  • 725
  • 1
  • 7
  • 9

14 Answers14

114

Go to your Android SDK installed directory then extras > android > support > v7 > appcompat.

in my case : D:\Software\adt-bundle-windows-x86-20140702\sdk\extras\android\support\v7\appcompat

once you are in appcompat folder ,check for project.properties file then change the value from default 19 to 21 as :

target=android-21.

Save the file and then refresh your project.

Then clean the project: In project tab , select clean option then select your project and clean...

This will resolve the error. If not, make sure your project also targets API 21 or higher (same steps as before, and easily forgotten when upgrading a project which targets an older version). Enjoy coding...

user149408
  • 5,385
  • 4
  • 33
  • 69
Sachin G S
  • 1,318
  • 1
  • 8
  • 10
  • Worked for me as well, but don't forget to target the library project to 21 when you change 19 to 21 in project.properties – Rahul Matte Aug 09 '15 at 03:48
  • 1
    An entire cookie factory! And a big bag of dogsh*t send over to Google. – Olof Hedman Sep 21 '15 at 12:38
  • will this make the app to be installed on devices which are >= API Level 21 ?? – Kamalakannan J Oct 14 '15 at 06:13
  • 1
    in my case I had to set android-23 but the solution worked. thanks a lot! For future reference, I came across this issue in Nativescript and the same solution worked – dragonmnl Jan 19 '16 at 20:45
  • 3
    I do not see project.properties file in C:\AppData\Local\Android\sdk\extras\android\m2repository\com\android\support\appcompat-v7. All I see is a list of folders for each SDK version, 18.00, 19.00, 19.0.2, 19.1.0, etc. – savi Feb 19 '16 at 22:03
  • Now the Android N (api 24) is released, I've set target=android-24, errors were fixed. – Eugene Gr. Philippov Jul 04 '16 at 00:56
  • If you’ve imported appcompat-v7 as a project in Eclipse, you can do this via the GUI. Simply go to Project Properties > Android, then choose the target API. Look for the API levels in the error messages and choose (at least) the highest API you see there. – user149408 May 14 '17 at 22:04
42

I've just solved these exact errors myself. The key it seems is that your project.properties file in your appcompat library project should use whatever the highest version of the API that your particular appcompat project has been written for (in your case it looks like v21). Easiest way I've found to tell is to look for the highest 'values-v**' folder inside the res folder (eg. values-v21).

To clarify, in addition to the instructions at Support Library Setup, your appcompat/project.properties file should have in it: target=android-21 (mine came with 19 instead).

Also ensure that you have the 'SDK Platform' to match that version installed (eg for v21 install Android 5.0 SDK Platform).

See also appcompat-v7:21.0.0': No resource found that matches the given name: attr 'android:actionModeShareDrawable'

Alternatively if you don't want to use the appcompat at all, (I think) all you need to do is right click your project > Properties > Android > Library > Remove the reference to the appcompat. The errors will still show up for the appcompat project, but shouldn't affect your project after that.

Community
  • 1
  • 1
Ben
  • 531
  • 3
  • 3
  • This is correct answer, thanks! In my case highest values were values-v23, so I had to compile project with sdk 23. – qkx Apr 29 '17 at 09:26
8

Prerequirements

Make sure that you've downloaded the latest extras as well as the Android 5.0 SDK via the SDK-Manager.enter image description here

back track
  • 209
  • 1
  • 6
6

This has happened to me after I "updated" into 5.0 SDK and wanted to create a new application with support library

In both Projects (project.properties file) in the one you want to use support library and the support library itself it has to be set the same target

e.g. for my case it worked

  1. In project android-support-v7-appcompat Change project.properties into target=android-21
  2. Cleanandroid-support-v7-appcompat In my project (where I desire support library)
  3. In my project, Change project.properties into target=android-21 and android.library.reference.1=../android-support-v7-appcompat (or add support library in project properties)
  4. Clean the project
pajus_cz
  • 1,261
  • 1
  • 13
  • 19
5

Your compile Sdk version is set to 21. change it to 20 or less. Its present in build.gradle in android studio. Then clean the project and rebuild it

Panther
  • 8,938
  • 3
  • 23
  • 34
  • im compiling using android 4.0.3 (api 15) – divinesense Oct 23 '14 at 14:50
  • Also im using eclipse as the ide – divinesense Oct 23 '14 at 14:50
  • well you should have recently updated the sdk and so the libraries should have added it automatically. Remove `appcompat_v7` from the `project properties` dependent libraries. Also make sure AndroidManifest.xml has `` less than 21. – Panther Oct 23 '14 at 14:53
  • Yea i did what u said and in my Androidmanifest.xml file the target sdk version is 15 but still there is an error error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'. styles_base.xml /appcompat_v7/res/values-v21) – divinesense Oct 23 '14 at 15:10
  • the other error is] R cannot be resolved to a variable MainActivity.java /Hellowworld/src/com/myfirst/hellowworld ] – divinesense Oct 23 '14 at 15:10
  • there is the small red cross in my package explorer at appcompat_v7/res/values-v21/styles_base.xml – divinesense Oct 23 '14 at 15:15
  • Also now im getting this error **error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. styles.xml /Hellowworld/res/values** – divinesense Oct 23 '14 at 15:24
  • If you are using `ActionBar` in your app use `Theme.AppCompat.Light.DarkActionBar` – Panther Oct 24 '14 at 02:50
4

My Project Build Target of android-support-v7-appcompat was with API 19 just changed it to API 20 it worked for me

Right click on android-support-v7-appcompat library project Go to properties Click on Android Change project build Target from Android 4.x.x to Android 5.0

This helped me hopefully it helps others too.

Somir Saikia
  • 1,610
  • 1
  • 16
  • 21
2

I followed all of those instructions including the instructions from Android. What finally fixed it for me was changing Project Build Target from API level to API level 21 in my project.

I am using API 22 (Android 5.1.1), which is newer than when these other answers were written. So you cannot set target=21 in the support library as you could 6 months ago.

Walker Rowe
  • 953
  • 1
  • 12
  • 24
2

I am writing application to API level 21, I tried all the above but didn't worked, Finally i deleted Values-v23 from appcompat_v7.It worked.

shiv
  • 127
  • 1
  • 3
  • 13
  • Finally a solution that works! The API level was always correct for me, and it still didn't work. With this solution it works. – Berit Larsen Feb 15 '16 at 15:53
0

After changing the target to matching version (as explained by Ben), if it still shows errors then just run "Clean" on the project to clear resource errors.

Ravi
  • 599
  • 4
  • 7
0

Well, it costed me 2 days to figure out the problem. In short, by default you shall just keep the max version to be the highest level you had downloaded, says, Level 23 (Android M) for my case.

otherwise you will get these errors. You have to go to project properties of both your project and appcompat to change the target version.

sigh.

Alfred Loh
  • 87
  • 6
0

For my Android Studio workout. I found that this happen when I change Compile SDK Version from API23 (Android 6) to be API17 (Android 4.2) manually in Project Structure setting, and trying to change some code in layout files.

I miss-understood that I have to change it manually, even on New Project I have selected the "Minimum SdK" to be 4.2 already.

Solve by just change it back to API23, and it still can run on Android 4.2. ^^

0
Download the latest "sdk platform" and "sdk build tools" of same version like 23.* for 
both from "sdk Managar".

(for reference see above hosted image from back track). Then right click on your project -> properties -> Android -> in "project build properties" select "API level" 23 or the latest one which you updated. Then clean your project once.

Note: But all three should be in same version.
Community
  • 1
  • 1
anand krish
  • 4,281
  • 4
  • 44
  • 47
0

please open your android sdk installed directory then,

in my path :

E:\Android\sdk\extras\android\support\v7\appcompat

then you can see " project.properties" file

open it and change target "target=android-19" to "target=android-23"

its worked for me.

thanks : https://stackoverflow.com/a/27243716/4140589

Community
  • 1
  • 1
jesto paul
  • 438
  • 11
  • 21
0

I solved similar problem by adding reference to the /appcompat project:

enter image description here