首页 文章

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

提问于
浏览
1

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

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

the error message

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

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

    buildscript {
        repositories {
            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
    }

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

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

无法解析com.android.support:appcompat-v7-26.1.0: . 要求:project: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

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

    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'
        }
    
  • 0
    • 确保您的机器已连接到互联网 .

    • 转到项目级 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
    }
    
    • 转到 File - > Settings &expand Build, Execution, Deployment - > Gradle - > UNCHECK Offline work - >确定

    • 转到 File - >点击 Invalidate Caches / Restart - > Invalidate & Restart

相关问题