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

AndroidAndroid LayoutAndroid StudioAndroid XmlAndroid Layoutparams

Android Problem Overview


  • 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][1]][1]

[![enter image description here][2]][2] [1]: http://i.stack.imgur.com/Igpr9.png [2]: http://i.stack.imgur.com/MN3lK.png

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

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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 - Android

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 - Android

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.

Solution 5 - Android

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)

Solution 6 - Android

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

Solution 7 - Android

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.

Solution 8 - Android

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

Solution 9 - Android

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.

Solution 10 - Android

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

Solution 11 - Android

I had to

  1. Delete Android SDK from AppData\Local\Android\Sdk
  2. Reinstall Android Studio

Solution 12 - Android

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://stackoverflow.com/a/53160674/6568421

Solution 13 - Android

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

Solution 14 - Android

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

Solution 15 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbhishekView Question on Stackoverflow
Solution 1 - AndroidMarius GheorgheView Answer on Stackoverflow
Solution 2 - AndroidMohamed AklView Answer on Stackoverflow
Solution 3 - AndroidmcoView Answer on Stackoverflow
Solution 4 - AndroidvovahostView Answer on Stackoverflow
Solution 5 - AndroidRacerView Answer on Stackoverflow
Solution 6 - AndroidDivakar RajeshView Answer on Stackoverflow
Solution 7 - AndroidHenrik Bøgelund LavstsenView Answer on Stackoverflow
Solution 8 - AndroidMohammad HadiView Answer on Stackoverflow
Solution 9 - AndroidMazen el SenihView Answer on Stackoverflow
Solution 10 - AndroidHuluView Answer on Stackoverflow
Solution 11 - AndroidSami RajalaView Answer on Stackoverflow
Solution 12 - AndroidAbdullah MorsiView Answer on Stackoverflow
Solution 13 - AndroidAshik AzeezView Answer on Stackoverflow
Solution 14 - AndroidTal FiskusView Answer on Stackoverflow
Solution 15 - AndroidSam de JongView Answer on Stackoverflow