Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding

  • 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()
    }
}

Solution 1:

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

Solution 2:

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://stackoverflow.com/a/53053438/7515903

Credits: @alexuz

Solution 3:

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

Credit: https://stackoverflow.com/a/47500156/5673746

Solution 4:

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.