18

I had created an app and when tried to run,get an error like this.

ERROR: In <declare-styleable> MenuView, unable to find attribute android:preserveIconSpacing

Problems enter image description here

and at end of R.java enter image description here

please help me to fix this issue

Sonia John Kavery
  • 2,099
  • 2
  • 20
  • 36

7 Answers7

26

I had the same problem in Eclipse, and fixed it by changing the API level by...

  • Right Clicking on the project
  • Open PROPERTIES > ANDROID
  • Changed the API level down to the one I had been using up to now.

I think I was having the problem because I had just switched from API 21 to 22. I had read earlier that API 22 was trouble-some, so people were not using it.

Hope that helps.

  • 6
    While this will remove the error, it doesn't really fix the underlying problem and allow the OP to use API 22. The correct fix is to update the version of the appcompat library so that it is compatible with API 22. – Code-Apprentice May 30 '15 at 13:02
  • 2
    This is not the correct answer. Update your appcompat version to 22. – Zach Sperske Jun 02 '15 at 19:13
  • to @ZachSperske & Code-Apprentice: It may not be the best practice / correct answer... However, it allowed me to move forward with work on my practice. As with all programming - sometimes we programmers may not know what is 'best practice' - or sometimes 'best practice' is complicated and seems unnecessary when there is a simpler way to do it which seems to work just as fine. – Sandi Laufenberg-Deku Nov 20 '15 at 21:03
  • Your solution prevents people from developing an app which targets the newer SDK. That's clearly not a good solution as it would trap your app on API 21. Stack overflow is about providing the most correct answer, yours is not a correct answer, just a workaround. – Zach Sperske Dec 01 '15 at 00:13
  • to @ZachSperske & Code-Apprentice: What is your solution that works? I did try updating appcompat lib. before posting my answer, and that did not work for me. – Sandi Laufenberg-Deku Jan 02 '16 at 03:05
  • what about api 23 – PHPFan Jan 12 '17 at 11:12
17

this error because you are using an old Appcompat version .. update Appcompat

to the newer version which is compatible with API 22

then click on fix project properties ..

working Fine with me :)

Hope This Help!!

Ramy Aly
  • 235
  • 2
  • 8
11

I think switched the API Level is not a genuine solution. We can resolve this by follows these steps:

  1. Go to "C:\Users\AjaySharma\AppData\Local\Xamarin\Android.Support.v7.AppCompat\20.0.0\content\support\v7\appcompat\res\values\attrs.xml"

    (Pleae make sure , change USer name and Target version in path)

  2. Find "android:preserveIconSpacing" in file and remove or comment this entire line.

  3. Now, You can Build Seccessfully. For more details. Read this

Community
  • 1
  • 1
Ajay Sharma
  • 2,881
  • 5
  • 22
  • 32
  • 1
    In OS X, the path for the step 1 is: `~/.local/share/Xamarin/Android.Support.v7.AppCompat/20.0.0/content/support/v7/appcompat/res/values/attrs.xml` – Alberto Estrella Apr 17 '15 at 00:50
  • You're changing a system library. This is very hackish. I'd suggest a different API level. – Dheeraj Bhaskar Apr 21 '15 at 19:07
  • Yes, you are saying right. But, for some change API level not works , So they can solve by doing this. – Ajay Sharma Apr 22 '15 at 05:20
  • 1
    This is not the correct solution. We as Android developers should not change the source for the appcompat support library...unless we actively contribute to it. – Code-Apprentice May 30 '15 at 12:40
  • Code-Apprentice If this is not the correct solution, then please tell the right solution so others can use that one to solve this issue. – Ajay Sharma Jun 01 '15 at 09:17
4

I fixed the problem by going to the path

E:\adt-bundle-windows\sdk\extras\android\support\v7\appcompat\res\values\attrs.xml and Find "android:preserveIconSpacing"

Then change it, From

attr name="preserveIconSpacing" format="boolean"

To

attr name="android:preserveIconSpacing"

also, remove

format="boolean"
Tushar Gogna
  • 4,963
  • 6
  • 31
  • 42
George Isaac
  • 569
  • 4
  • 9
  • You should not change the source code of the appcomat library. Instead you should update to the version of the library which are made for your chosen compileSdkVersion as described by Ramy Sky and Alexander Garner. – Code-Apprentice Jun 01 '15 at 16:54
4

In my case for the same error, when all else failed, I removed this line from Gradle config file, myproject/app/build.gradle

config:compile 'com.android.support.constraint:constraint-layout:1.0.2'

and, voila! It worked.

kmonsoor
  • 7,600
  • 7
  • 41
  • 55
2

I had this problem after upgrading my version of Eclipse (and Google Plugin):

ERROR: In MenuView, unable to find attribute android:preserveIconSpacing

I have solved it by deleting the appcompat_v7 project from my workspace (and my disk).

And then creating a new Android project MyApp1 - which has recreated the appcompat_v7 project (here fullscreen):

screenshot

After that I have deleted the MyApp1 project again.

Community
  • 1
  • 1
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
-1

if all the above answers don't work for you are probably missing

apply plugin: 'com.google.gms.google-services'

in you app build.gradle