Gradle升级后无法解析依赖关系

时间:2018-01-10 03:18:41

标签: android android-gradle build.gradle

我升级了AS,错误开始出现 我看着每一个地方,我无法解决问题

--compression-codec snappy

the error message

这是我的build.gralde(项目),离线未选中,我做了无效并重新启动无效,

apply plugin: 'com.android.application'

android {
    buildToolsVersion "26.0.2"
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.student.myapplication"
        minSdkVersion 23
        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 {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7-26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

这意味着什么无法解决依赖? 这是我将存储库添加到gradle(app)时得到的结果

错误:无法解析所有配置文件':app:debugCompileClasspath'。

  

无法解析com.android.support:appcompat-v7-26.1.0:。     要求:         项目:app   无法解析com.android.support:appcompat-v7-26.1.0:。   无法获得资源' https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   无法获得' https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径   无法解析com.android.support:appcompat-v7-26.1.0:。   无法获得资源' https://jcenter.bintray.com/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   无法获得' https://jcenter.bintray.com/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径   无法解析com.android.support:appcompat-v7-26.1.0:。   无法获得资源' https://repo1.maven.org/maven2/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   无法获得' https://repo1.maven.org/maven2/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。   sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径   无法解析com.android.support:appcompat-v7-26.1.0:。   无法获得资源' https://maven.google.com/com/android/support/appcompat-v7-26.1.0//appcompat-v7-26.1.0-.pom'。

我看了gradle控制台,我找到了问题所在的链接,我点击了它们,然后在浏览器中打开了错误404 gradle console

2 个答案:

答案 0 :(得分:0)

您可以尝试将这些添加到您的依赖项中。

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

这应该是它的样子。

apply plugin: 'com.android.application'

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

    android {
        buildToolsVersion "26.0.2"
        compileSdkVersion 26
        defaultConfig {
            applicationId "com.student.myapplication"
            minSdkVersion 23
            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 {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7-26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    }

答案 1 :(得分:0)

  1. 确保您的设备已连接到互联网。
  2. 转到项目级别build.gradle文件,它应如下所示:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    
        repositories {
            google()
            jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    
    
        // 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
    }
    
  3. 转到文件 - > 设置&展开构建,执行,部署 - > Gradle - > UNCHECK 离线工作 - >确定

  4. 转到文件 - >点击使缓存无效/重新启动 - > 无效&重新启动