如何使用最新的支持库(使用支持库26.0.2和compileSDKVersion 26解决错误失败)?

时间:2017-09-05 06:03:07

标签: android android-gradle

我已将compileSdkVersion更新为26.这就是我的gradle文件现在的样子。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId ##############
        minSdkVersion 21
        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'
        }
    }
}

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'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    testCompile 'junit:junit:4.12'
}

可以预见,我会在支持库(25.3.1)和CompileSdkVersion(26)的版本中收到不匹配(?)的警告。

我尝试将支持库版本更新为以下版本:

  • 编译'com.android.support:appcompat-v7:26.0.0'
  • 编译'com.android.support:appcompat-v7:26.0.2'

问题

他们都没有奏效。两种情况都显示Failed to resolve个错误。点击Install Repository and sync project冻结Android Studio几秒钟,没有其他事情发生。

我错过了什么吗?

最新的Android支持版本库here26.0.2

2 个答案:

答案 0 :(得分:32)

您应该在 App Level build.gradle 部分添加此内容。

<强>最后

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

然后 Clean-Rebuild Run

<强> FYI

如果您使用的是 Gradle higher than 4.1 版本,则必须使用:

allprojects {
      repositories {  
        google()

    }
}

答案 1 :(得分:-1)

转到文件 - &gt;设置 - &gt; Android SDK-&gt; SDK工具。 然后在Support Repository下拉列表中,选中android support repository复选框并更新它。

相关问题