Android Studio cannot resolve symbol 'TabLayout'

眉间皱痕 提交于 2019-11-27 14:31:41

问题


Cannot resolve symbol TabLayout ? How to clear this error? Please help me. I already imported import android.support.design.widget.TabLayout;


回答1:


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



回答2:


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 \app\build.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




回答3:


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.




回答4:


Android Studio no longer uses "compile", they use "implementation". Be sure to include the code below when you go to Build Gradle>dependencies{

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}




回答5:


I solve it by Open build.gradle (Module: app) and add

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



来源:https://stackoverflow.com/questions/32686324/android-studio-cannot-resolve-symbol-tablayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!