android studio更新后的Gradle错误

时间:2017-11-17 17:06:13

标签: android android-studio gradle android-gradle build.gradle


今天我将android studio更新为3.0版 之后我无法成功建造项目 我收到了这些错误:

Unable to resolve dependency for ':app@release/compileClasspath': could not resolve com.android.support:appcompat-v7:27.0.1.

我尝试过使用VPN或代理等,但没有一个工作 这是漫长的一天。我希望你能帮助我。

这是我的build.gradle(app):

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "ir.hetbo.kotlin_tutorial"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

这是build.gradle(项目):

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

buildscript {
ext.kotlin_version = '1.1.60'
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

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

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

我做了很多事情来修复它,但每次都失败了。

我使用gradle 4.3.1

这里是gradle包装器属性:

#Sat Nov 18 10:16:45 IRST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip

4 个答案:

答案 0 :(得分:4)

使用 gradle 4.1 的新功能和 classpath' com.android.tools.build:gradle:3.0.0'

  

distributionBase = GRADLE_USER_HOME distributionPath = wrapper / dists   zipStoreBase = GRADLE_USER_HOME zipStorePath = wrapper / dists   distributionUrl = https://services.gradle.org/distributions/gradle-4.1-all.zip

并且这是build.gradle(项目):

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

buildscript {
ext.kotlin_version = '1.1.60'
repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()

}
}

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

答案 1 :(得分:0)

从新版本开始,这些库现在位于maven内,不在Jcenter内。

因此,在您的gradle文件中,您必须添加maven,如下所示:

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

此链接可以为您提供帮助:Adding support libraries

答案 2 :(得分:0)

整个项目有一个build.gradle文件,每个模块有一个。 需要在应用程序build.gradle文件中添加以下代码。

 buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.2'
        }
    }

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

答案 3 :(得分:0)

在build.gradle(Project)中尝试此代码:

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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