122

After updating Android Studio from 2.3 to 3.0 I changed buildToolsVersion from 26.0.0 to 26.0.2 and after that I am getting this error:

Cannot resolve symbol '?attr/actionBarSize

Xml code:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:titleTextColor="@android:color/white"/>

Dependencies:

compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
Rahul Roshan
  • 1,501
  • 2
  • 11
  • 14

16 Answers16

249

Nothing helped, but changing:

?attr/actionBarSize to ?android:attr/actionBarSize did the job.

That's actually a bug in few versions. Even if you won't fix it, Android will automatically fix it at runtime.

Victoria Klimova
  • 2,795
  • 1
  • 11
  • 12
  • 20
    I think `?android:attr/actionBarSize` is only compatible with api 21, `?attr/actionBarSize` requires a pre-21 sdk installed for Android Studio to see it. The other issue for me was making sure the compileSdk and support libs have the same major version number (27 in my case) – Daniel Wilson Apr 06 '18 at 18:32
  • 2
    Hmmm, seems a little magical, but it works. I'd love to see a definitive explanation that describes precisely what breaks with the various sdks and what works and why. – SMBiggs May 16 '18 at 05:22
  • it seems like a bug because the project compile and build ok with this error. – LMaker Aug 02 '18 at 20:04
34

Update all your library versions to 26.1.0 (to the most recent version) and also add:

compile 'com.android.support:support-v4:26.1.0'

if you are using Android Studio 3.0.0 and above then use

implementation 'com.android.support:support-v4:26.1.0'

Sync your project and the error will automatically resolve because ?attr/actionBarSize is part of v4 library.

  • specify which library version you are talking about – D_Alpha Oct 31 '17 at 11:50
  • I had to change : implementation 'com.android.support:support-v4:26.1.0' to compile 'com.android.support:support-v4:26.1.0' – Louis Parkin Mar 08 '18 at 16:11
  • 1
    Use `implementation` instead of `compile` now. – Suragch Apr 07 '18 at 02:13
  • I think this answer should not be the selected answer. Because it forces you to use the support-v4 library when you don't have to. You can Sid and Victoria Klimova's answer is the best answer, you can avoid using unnecessary library in your project easily... – Evren Yurtesen Apr 13 '18 at 12:23
  • This answer didn't even help me. Sid's answer helps, but I don't understand why do I need `android:` prefix when I have already added `android` namespace `xmlns:android="http://schemas.android.com/apk/res/android"` does anybody know? – user1209216 Apr 17 '18 at 06:37
  • This answer was true for older version of android studio but now it's not working for new version so I am accepting @VictoriaKlimova's answer as correct. Thanks EvrenYurtesen for pointing this. – Rahul Roshan May 08 '18 at 04:23
  • I agree with @Suragch compile has is being replaced with implementation – George Jul 01 '18 at 18:02
28

In the project directory hierarchy switch "Android" to "Project". Then delete a folder ".idea/libraries", only "libraries". Select an option from the menu "File -> Invalidate Caches / Restart... -> Invalidate and Restart".

11

Good day, I know this is a bit late.

but I have encountered this one too, when I updated to Android Studio 3.0

what i did is I changed

compile 'com.android.support:support-v4:26.1.0'

to

implementation 'com.android.support:support-v4:26.1.0'

Hope it can help somebody.

Chris Palma
  • 223
  • 1
  • 2
  • 13
4

This is what I did to fix exactly the same problem. 1. Go to SDK manager. 2. Check Android API 27 and Android 8.0 (Oreo) 3. Click "Apply" to download and install those SDKs 4. In build.gradle, change the 'buildToolsVersion "26.0.1"' to 'buildToolsVersion "26.0.2"' and do a gradle sync.

Hope this can help fix your issue.

3

Your buildToolsVersion version differs from version in dependencies (e.g. buildToolsVersion is 27.0.0 but implementation 'com.android.support:support-v4:27.0.1'). Make them the same.

Andrew Glukhoff
  • 898
  • 11
  • 9
2

my problem solved by changing compileSdkVersion and targetSdkVersion from 26 to the last version 27, also u need to upgrade ur dependencies to 27.

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com......"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:design:27.1.0'
}

hope this solve ur problem too :)

IRvanFauziE
  • 823
  • 11
  • 16
1

Try to add this in your build.gradle(app) dependencies:

resolutionStrategy {
    force libraries.support.appCompat
    force libraries.support.design
    force 'com.android.support:support-utils:26.0.1'
    force 'com.android.support:support-compat:26.0.1'
}
milosmns
  • 3,595
  • 4
  • 36
  • 48
petrrr33
  • 583
  • 9
  • 24
1

This worked.

I have updated the compile and support lib versions from 26.x.x to 27.x.x.

Mahi
  • 472
  • 5
  • 7
1

I tried all the answers here and so many others from lots of places but only the below techniques worked for me. The simple way is you just need to close the project then import the same project as a Gradle project Or you can go to Project structure -> project -> change Gradel plugin = 4.4 and Android plugin version = 3.1.4. Both of these above methods work.

Note: These versions(4.4, 3.1.4) are latest when I write this answer please use the latest version instead of these.

Biswajit
  • 1,829
  • 1
  • 18
  • 33
1

Same issue here, if you're using AndroidX add this :

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
1

Change R.attr.actionBarSize to androidx.appcompat.R.attr.actionBarSize.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
0

Maybe you hava upgraded the version of gradle. when my gradle version is 4.4 and plugin version is 3.1.1.It is ok.

enter image description here

Evan
  • 214
  • 3
  • 8
0

this work:

delete all file in $HOME/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar

Better
  • 165
  • 1
  • 13
0

Changed all Support Library versions to the newest 27.1.1 and the error was gone.

Darush
  • 11,403
  • 9
  • 62
  • 60
0

please replace android support libraries.

from

27.1.1

to

28.0.0-alpha3

and replace 27 to 28 for following cases:

compileSdkVersion 28
buildToolsVersion "28.0.0"
targetSdkVersion 28

this will fix the issue.

Ahamadullah Saikat
  • 4,437
  • 42
  • 39