如何解决此错误:无法解决:com.android.support:appcompat-v7:26.1.0

时间:2017-12-09 12:14:22

标签: android gradle dependencies android-appcompat

我刚刚安装了Android Studio 3.0.1,并且我尝试了上一次提出这个问题的许多解决方案,但它们似乎都没有工作。我仍然收到此错误:无法解决:com.android.support:appcompat-v7:26.1.0

我的顶级构建文件如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

    allprojects{
        repositories{
            jcenter()
        }
    }
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android plugin 3.0.0 or higher.
        maven { url "https://maven.google.com" }
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

我的app build.gradle文件包含:

apply plugin: 'com.android.application'

repositories {
    maven { url "https://maven.google.com" }
    jcenter { url "http://jcenter.bintray.com/" }
}

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        applicationId "com.example.application"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:design:23.1.1'
}

3 个答案:

答案 0 :(得分:1)

制作'com.android.support:design:23.1.1' - 与appcompat-v7相同的版本。然后从app gradle

中删除

repositories { maven { url "https://maven.google.com" } jcenter { url "http://jcenter.bintray.com/" } }

答案 1 :(得分:1)

您的项目build.gradle应与此类似

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.0.1"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

你应该为你的库使用相同的版本:

implementation "com.android.support:appcompat-v7:26.0.1"
implementation "com.android.support:design:26.0.1"

答案 2 :(得分:0)

问题的原因是以下代码。

allprojects{ repositories{ jcenter() } }

将其替换为

allprojects { repositories { google() jcenter() } }

如果它能解决您的问题,请告诉我。