【问题标题】:Failed to resolve: com.android.support:support-v13:26 [duplicate]无法解决:com.android.support:support-v13:26 [重复]
【发布时间】:2017-09-22 09:04:42
【问题描述】:

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

我不明白为什么我以前编译良好的所有导入现在都简单地说:

无法解决:com.android.support:support-v13:26

无法解决:com.android.support:appcompat-v7:26

并且没有提供任何按钮(例如“安装存储库和同步项目”)是可点击的。

请看一下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'
}

我尝试过“使缓存无效/重新启动”,但没有任何影响。

附言

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

这么说

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

这也会导致问题吗?

【问题讨论】:

  • 不管怎样,所有支持库使用相同的版本

标签: java android gradle android-support-library


【解决方案1】:

如果你编译的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'
        }
    }
}

【讨论】:

  • 不准确。如果你编译的 SDK 版本是 26,android 支持依赖版本应该是 26.x.x。这是警告而不是错误。
  • @GabrieleMariotti,是的,你是对的。我已经编辑了我的答案。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多