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'
2
  • Maybe you hava upgraded the version of gradle.
    – Evan
    Apr 24, 2018 at 10:35
  • Trying clicking Build > Clean Project
    – Michael N
    Nov 29, 2021 at 17:52

16 Answers 16

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.

3
  • 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) Apr 6, 2018 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, 2018 at 5:22
  • it seems like a bug because the project compile and build ok with this error.
    – LMaker
    Aug 2, 2018 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.

7
  • specify which library version you are talking about
    – D_Alpha
    Oct 31, 2017 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' Mar 8, 2018 at 16:11
  • 1
    Use implementation instead of compile now.
    – Suragch
    Apr 7, 2018 at 2: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... Apr 13, 2018 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? Apr 17, 2018 at 6:37
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".

2
  • 3
    This worked for me too. But curious, why it did. What exactly does "Invalidate Caches / Restart" do? Jul 23, 2018 at 19:28
  • Thanks. It worked for me with com.android.support:support-v4:27.1.1
    – Arash
    Oct 5, 2018 at 7:33
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.

1
  • support_library = '27.1.1' to support_library = '27.1.0' worked for me. not sure why downgrading fixed. Jun 6, 2018 at 22:25
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.

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 :)

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'
}
1

This worked.

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

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.

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.

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

0

this work:

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

0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.