解析失败:com.android.support:support-v13:26

Failed to resolve: com.android.support:support-v13:26

在我将 TabLayout 添加到 .xml 布局之前,一切都在正常工作和编译。在我添加它之后,该项目只是拒绝编译并且我所有的 .xml 文件都停止显示任何内容并且我所有的库导入都显示“无法解析符号 ...”。

我不明白为什么我之前编译良好的所有导入现在只是说:

Failed to resolve: com.android.support:support-v13:26

Failed to resolve: com.android.support:appcompat-v7:26

和 none 提供的按钮(例如“安装存储库和同步项目”)是可点击的。

请看一下 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.prett.myapplication"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    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:26'
    compile 'com.android.support:support-v13:26'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.3.1'
}

我试过“使caches/restart无效”,但没有任何效果。

P.S.

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

This support library should not use a different version (25) than the compileSdkVersion (26)

这也会导致问题吗?

在 gradle 中尝试以下依赖项并重建项目;

compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:design:26.0.1'

此支持库不应使用与 compileSdkVersion (26) 不同的版本 (25)

意味着您必须将支持库从版本 25 更新到 26,问题将得到解决。

如果你的编译SDK版本是26,android支持的依赖版本应该是26.x.x

按如下方式设置您的 gradle 依赖项:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    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:26.0.1'
    compile 'com.android.support:support-v13:26.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.0.1'
}

如果仍然出现编译错误,请将 google maven 存储库添加到 Project Gradle 文件:

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
}