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()
    }
}
Abhishek
  • 2,350
  • 2
  • 21
  • 35

16 Answers16

56

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

Marius Gheorghe
  • 607
  • 5
  • 7
  • 13
    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. – Kirill Starostin May 23 '18 at 05:31
  • 10
    And in 3.1.2 it's far left, between "Save All" and "Sync with File System". – Jake Lee Jun 28 '18 at 15:48
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://stackoverflow.com/a/53053438/7515903

Credits: @alexuz

Allan Veloso
  • 5,823
  • 1
  • 38
  • 36
Mohamed Akl
  • 652
  • 5
  • 14
  • Similar solution here (to a different problem) that worked for me: https://stackoverflow.com/a/52687462/1617737 – ban-geoengineering Mar 25 '19 at 19:26
  • 1
    I tries everything everyone suggested, nothing helped. I deleted everything inside c:\Users\\.gradle\caches\ and it fixed it (I took it from https://stackoverflow.com/a/53053438/7515903, but I didn't need to delete the other suggestion) – Tiferet Cohen Nov 25 '18 at 15:53
  • 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. sad – Jakub Kostka Jun 17 '19 at 11:10
16

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

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

mco
  • 1,809
  • 15
  • 31
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.

vovahost
  • 34,185
  • 17
  • 113
  • 116
  • 2
    Funny. For me, invalidate caches didn't work but sync with Gradle did. Guess there are multiple potential causes to this issue. – methodsignature Oct 29 '18 at 12:31
  • Sometimes just closing ad reopening Android Studio can fix this type of issues. – vovahost Dec 21 '18 at 09:17
  • Tried that but it didn't work. I did a similar thins: deleted C:\Users\.AndroidStudio3.2\system\caches. See stackoverflow.com/a/52965770/8648075 as @M.J.M suggested. – Hristova Jan 05 '19 at 23:16
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.

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)
Racer
  • 152
  • 1
  • 9
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

Divakar Rajesh
  • 1,140
  • 2
  • 18
  • 23
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
Mohad Hadi
  • 1,826
  • 3
  • 24
  • 39
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.

Mazen el Senih
  • 101
  • 1
  • 4
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)

aamitarya
  • 719
  • 6
  • 11
1

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

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Hulu
  • 11
  • 1
  • 1
    After trying everything else on this list, my only solution was to reinstall from scratch. What a waste of time! – Panos Gr Nov 03 '18 at 18:13
1

I had to

  1. Delete Android SDK from AppData\Local\Android\Sdk
  2. Reinstall Android Studio
Sami Rajala
  • 191
  • 1
  • 11
1

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

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • 4
    I had the same issue with 33. I fell back to 32 and it's working again. – Dustin Aug 20 '22 at 19:38
  • 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. – Hemanth Kumar Sep 27 '22 at 14:24
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://stackoverflow.com/a/53160674/6568421

0

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

Ashik Azeez
  • 404
  • 5
  • 8
0

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

Tal Fiskus
  • 131
  • 3