Android Studio cannot resolve symbol ‘TabLayout’

Had a similar problem, to fix this in Android Studio (AS) I went Build->Clean Project and AS sorted everything out. Make sure in your build.gradle file under dependencies that you have:

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

I solved the issue Manually by adding the following two lines:

implementation 'com.android.support:support-v4:22.2.0'
implementation 'com.android.support:design:22.2.0'

under dependencies in appbuild.gradle worked for me.

Note: Your all the support libraries have to be the same version i.e. appcompat-v7 and support-v4 to same version e.g. 23.0.1; otherwise you can get this error

java.lang.NoClassDefFoundError: android.support.v7.internal.widget.TintManager`
after code build

Under Gradle Scripts,
Open build.gradle (Module: app)

Inside of dependencies add

compile 'com.android.support:design:25.3.1'

There may be a newer version of the library available, the android studio lint check may detect that.

The full dependencies area may look like this for reference. The above line is the only one I manually added.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.3.1'
}

An above answer suggested adding

compile 'com.android.support:design:+'

Which is kind of dangerous because it always uses the latest library, you may have trouble isolating bugs with automatic library updates happening in the background.

Leave a Comment