78
  • 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,130
  • 2
  • 15
  • 32

15 Answers15

54

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

Marius Gheorghe
  • 577
  • 4
  • 7
  • 11
    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
  • 9
    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
47

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
  • 3,918
  • 1
  • 27
  • 32
Mohamed Akl
  • 612
  • 5
  • 14
  • Could you please provide more details than just a link, in case the linked answer is deleted or changed in the future? – TheIT Dec 20 '18 at 00:04
  • @TheIT thanks for your suggestion, I have edited the response – Mohamed Akl Jan 16 '19 at 03:45
  • 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
  • 1
    The best answer! Thanks you lot – shariful islam Jan 09 '20 at 19:22
  • 1
    Thanks. It also fixed all the connections in my project. – SportAtomDroid Jan 21 '20 at 16:09
14

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,633
  • 11
  • 25
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
  • 25,072
  • 12
  • 95
  • 99
  • 1
    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

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
  • 130
  • 1
  • 8
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
  • 576
  • 2
  • 12
  • 18
5

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.

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
Mohammad Hadi
  • 1,246
  • 3
  • 16
  • 30
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
1

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

Eric Aya
  • 68,765
  • 33
  • 165
  • 232
Hulu
  • 11
  • 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´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
  • 368
  • 4
  • 7
0

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

Tal Fiskus
  • 11
  • 2
-1

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

Yunnosch
  • 21,438
  • 7
  • 35
  • 44
  • Please leave the decision whether this solves "it" to the question author. Also keep speculation out of the answer. You can write it into a comment (on your own post you can). – Yunnosch Sep 03 '20 at 20:57