Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding
Asked Answered
C

16

90
  • Getting Unknown attribute error on all android tag.

  • In layout XML, Auto suggestion is not showing all attributes (like layout_width, layout_height, orientation, orientation & all others android attributes.)

Here is a Snap shot

enter image description here

enter image description here Things i have done to resolve this issue.

  • Clean Build & Rebuild
  • Deleted .idea file
  • Invalidated Caches/ Restart.. option
  • Turn On Power Save Mode.

SDk is up to date.

In App Level Gridle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.abhishek.ondemandservice"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
        }
    }
}

Application level Gride.

buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        mavenCentral()
    }
}
Chasitychasm answered 10/2, 2016 at 6:57 Comment(4)
classpath 'com.android.tools.build:gradle:2.0.0-beta2'Pisciculture
why do i use older version if it works perfect in other systems and it's not working that way.Chasitychasm
You might want to accept one of the answers if they fixed your issueKrieger
This worked for me check this llink https://mcmap.net/q/246119/-unknown-attribute-android-error-on-android-studio-3-2-1Irritate
R
56

Just go to Tools->Android->Sync Project with Gradle Files

Rhinoceros answered 14/12, 2017 at 9:26 Comment(2)
Just to add - in Android Studio 3.1 there's a button called "Sync project with gradle files" between "revert" and "avd manager" buttons in a right corner of a toolbar.Grimace
And in 3.1.2 it's far left, between "Save All" and "Sync with File System".Piscatorial
D
51

The only thing that worked for me was cleaning the following folders:

c:\Users\<user>\.gradle\caches\
c:\Users\<user>\.AndroidStudio3.2\system\caches\

Android Studio will just redownload the libraries and caches them which will enable everything back to normal.

Source: https://mcmap.net/q/246120/-unknown-attribute-android

Credits: @alexuz

Derogate answered 30/10, 2018 at 15:23 Comment(3)
I tries everything everyone suggested, nothing helped. I deleted everything inside c:\Users\<user>\.gradle\caches\ and it fixed it (I took it from https://mcmap.net/q/246120/-unknown-attribute-android, but I didn't need to delete the other suggestion)Geraint
Similar solution here (to a different problem) that worked for me: https://mcmap.net/q/246121/-no-idea-annotations-attached-to-the-jdk-1-8-c-some-issues-will-not-be-foundTaneshatang
This solved my problem. But not the first time I have to solve this such a problem by literally rebuilding my entire project. Almost every AS update is the same. Wish iOS was bigger so I could just switch to that. sadCorrugation
A
16

To fix, change something in your gradle file, then sync gradle again. This worked for me.

Credit: https://mcmap.net/q/246122/-android-studio-unknown-attribute-in-xml-and-namespace-not-found

Assertion answered 30/11, 2017 at 20:36 Comment(1)
Worked like magic.. Been stuck on this for almost three days! Thanks a lot.. I wish you less bugs!Khabarovsk
N
11

I tried:

  • Removing the build folders
  • Cleaning the project
  • Sync Project with Gradle Files

But nothing worked. Finally using File > Invalidate caches fixed the error.

Neel answered 11/1, 2018 at 15:23 Comment(3)
Funny. For me, invalidate caches didn't work but sync with Gradle did. Guess there are multiple potential causes to this issue.Automatism
Sometimes just closing ad reopening Android Studio can fix this type of issues.Neel
Tried that but it didn't work. I did a similar thins: deleted C:\Users\.AndroidStudio3.2\system\caches. See https://mcmap.net/q/246119/-unknown-attribute-android-error-on-android-studio-3-2-1 as @Irritate suggested.Undercoat
M
6

Had the same issue, but after a reinstall of visual studio, so what helped for me on Android studio 3.2, was to go and upgrade the target version to 28 and compile version 28. Was at version 27 before.

I had to upgrade these packages as well

implementation "com.android.support:support-v4:28.0.0"
implementation 'com.android.support:support-core-ui:28.0.0'

After Gradle had synced then it worked for me.

Mackle answered 11/10, 2018 at 9:2 Comment(0)
A
6

Any of these ways will possibly fix your problem (unknown attribute android:layout-width)

  1. Sync project with Gradle file (File -> Sync project with Gradle files)
  2. Invalidate cache and restart (File -> Invalidate cache and restart -> Invalidate and restart)
  3. Delete .gradle and .idea file from the project folder and rebuild the project.
  4. Delete caches folder from Android studio (.AndroidStudio3.2 -> system -> caches)
Auburta answered 8/2, 2019 at 10:15 Comment(0)
I
5

I too encountered this..

  1. Just delete the .idea folder that is in the project location

  2. Build > Clean Project

  3. Then change something in the app level gradle

Then android studio will ask you to sync the project. Go ahead and sync, the problem will be gone

Inset answered 15/12, 2017 at 3:38 Comment(0)
P
3

if non of above answers dosn't work do these steps:

  1. first close android studio.
  2. than just go to windows>User or AppData>local> and delete androidstudio last version folder
  3. reopen androidstuduio and set default settings
Pelting answered 7/11, 2018 at 10:40 Comment(0)
C
2

In my case none of the above solutions worked for me, but changing the minSdkVersion to a higher version and doing a gradle sync after that did the trick, maybe this would be useful to somebody.

Clymer answered 26/4, 2018 at 20:5 Comment(0)
I
2

If you're facing this issue only for a few of the attributes like android:text or android:layout_margin, etc, check if your compileSdkVersion is 33 in gradle, and try downgrading it to 32 in build.gradle(:app)

Inattentive answered 26/9, 2022 at 10:4 Comment(0)
V
1

None of the existing suggestion works for me. I solved this issue by reinstalling Android Studio. Really weird.

Vibrant answered 5/10, 2018 at 3:46 Comment(1)
After trying everything else on this list, my only solution was to reinstall from scratch. What a waste of time!Selfexistent
B
1

I had to

  1. Delete Android SDK from AppData\Local\Android\Sdk
  2. Reinstall Android Studio
Benedikta answered 18/10, 2018 at 5:15 Comment(0)
T
1

I changed the compileSdkVersion/buildToolsVersion/targetSdkVersion from 30 to 29 in build.gradle and the problem disappeared for me.

Triatomic answered 3/9, 2020 at 20:27 Comment(2)
I had the same issue with 33. I fell back to 32 and it's working again.Air
Hi For me also same issue happened, So changed compile and target sdk versions from 33 to 32 then everything is working fine, But still I do't understand why android studio is not able to synch app properly with sdk 33.Autobus
S
1

I´ve tryed all the solutions but the only thing that worked for me was 4gus71n's answer.

Deleting the C:\Users.AndroidStudio3.2\system\caches folder solved my problem.

Link to his answer: https://mcmap.net/q/246122/-android-studio-unknown-attribute-in-xml-and-namespace-not-found

Sturdy answered 8/9, 2020 at 13:34 Comment(0)
W
0

I just changed my android SDK path and restart android studio->set new SDK path it working

Waterhouse answered 16/11, 2018 at 19:1 Comment(0)
E
0

Just update your android studio: Help -> Check for Updates..

Elevation answered 11/9, 2019 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.