Cannot resolve symbol '?attr/actionBarSize' after updating Android Studio from 2.3 to 3.0 for buildToolsVersion '26.0.2'

AndroidAndroid LayoutAndroid ActionbarAndroid Studio-3.0

Android Problem Overview


After updating Android Studio from 2.3 to 3.0 I changed buildToolsVersion from 26.0.0 to 26.0.2 and after then 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'

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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.

Solution 3 - Android

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".

Solution 4 - Android

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.

Solution 5 - Android

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.

Solution 6 - Android

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.

Solution 7 - Android

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

Solution 8 - Android

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

Solution 9 - Android

This worked.

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

Solution 10 - Android

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.

Solution 11 - Android

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

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

Solution 12 - Android

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

Solution 13 - Android

this work:

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

Solution 14 - Android

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

Solution 15 - Android

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.

Solution 16 - Android

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

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
QuestionRahul RoshanView Question on Stackoverflow
Solution 1 - AndroidVictoria KlimovaView Answer on Stackoverflow
Solution 2 - AndroidKunwar Ajeet Singh RajputView Answer on Stackoverflow
Solution 3 - AndroidOleh KholiavchukView Answer on Stackoverflow
Solution 4 - AndroidChris PalmaView Answer on Stackoverflow
Solution 5 - AndroidBaoqiang YanView Answer on Stackoverflow
Solution 6 - AndroidAndrew GlukhoffView Answer on Stackoverflow
Solution 7 - AndroidIRvanFauziEView Answer on Stackoverflow
Solution 8 - Androidpetryk33View Answer on Stackoverflow
Solution 9 - AndroidMahiView Answer on Stackoverflow
Solution 10 - AndroidBiswajitView Answer on Stackoverflow
Solution 11 - AndroidMouaad Abdelghafour AITALIView Answer on Stackoverflow
Solution 12 - AndroidEvanView Answer on Stackoverflow
Solution 13 - AndroidBetterView Answer on Stackoverflow
Solution 14 - AndroidDarushView Answer on Stackoverflow
Solution 15 - AndroidAhamadullah SaikatView Answer on Stackoverflow
Solution 16 - AndroidCoolMindView Answer on Stackoverflow