解析 compileClasspath 的依赖项时出错

Error in resolving Dependencies for compileClasspath

我在 android studio 上的项目工作正常,然后今天我重新打开它,gradle 无法构建。它在我的应用级别 gradle 中显示错误。我试图将代码复制到另一个项目,但当我尝试集成 google 的 gms 插件时,它的 gradle 也崩溃了。

我已经尝试更改插件的版本,但没有帮助。

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.abc.xyz"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'

    implementation 'com.google.android.material:material:1.0.0'

    implementation 'com.commit451:PhotoView:1.2.4'

    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    implementation 'com.google.zxing:core:3.3.0'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

    implementation 'com.squareup.okhttp:okhttp:2.7.5'

    implementation 'com.github.ivbaranov:materiallettericon:0.2.3'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

apply plugin: 'com.google.gms.google-services'

错误信息是

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.navigation:navigation-runtime:[2.2.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-impl:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-sdk-api:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.navigation:navigation-runtime:[2.2.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-impl:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-sdk-api:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve androidx.navigation:navigation-runtime:[2.2.1].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-impl:[17.2.2].
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-sdk-api:[17.2.2].
Show Details
Affected Modules: app

请帮忙!!

编辑:这些设置在离线 gradle 模式下工作正常,但当我上网时它们不会构建。 顶级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.5.3'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta02'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

打开顶级 gradle 文件并添加类路径 'com.google.gms:google-services:x.x.x',如下所示:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

好吧,显然我的 gradle 文件已损坏,我刚刚删除了 .gradle 文件夹并重建了项目,一切似乎都运行良好,感谢您的帮助。

使用此依赖项:

implementation 'com.google.firebase:firebase-crashlytics:17.2.2'

而不是:

implementation 'com.crashlytics.sdk.android:crashlytics:17.2.2'