【问题标题】:Gradle sync failed due to "Unable to resolve dependency" error由于“无法解决依赖关系”错误,Gradle 同步失败
【发布时间】:2019-10-06 21:21:58
【问题描述】:

我突然收到这个错误,我不知道如何解决这个问题。我已经在这里尝试了所有建议Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve,但对我没有任何帮助。

我已经尝试过的:

  • 按照建议将我的 sourceCompatibility 和 targetCompatibility 从 1.7 更新为 JavaVersion.VERSION_1_8
  • 已删除 .idea 文件夹
  • 已删除 google-services 插件,在 .gradle (app) 中实现 'com.google.android.gms:play-services-auth:17.0.0' 和 .gradle (project) 中的 google 服务类路径 --> 错误仍然发生
  • 当我将项目文件中的 google-services 类路径更新到最新版本 4.3.2 时,出现此错误
  • 删除了 google-services.json 并下载了一个新的
Could not resolve com.google.gms:google-services:4.3.2.
...
Remote host closed connection during handshake
  • 我使缓存/重启无效
  • 在 SDK 管理器中,Android SDK 显示为部分安装 --> 点击显示包详细信息 --> 没有要安装的内容,所有内容都显示为已安装
  • 在 misc.xml 文件中,语言级别已从 JDK 1_7 更新到 1_8

这可能也是我现在面临的一个问题,这可能是导致此问题的原因:

以前我安装了 SDK 29,但在 SDK 管理器中显示为“部分安装”,但当我单击“显示包详细信息”时,没有任何可安装的内容。我想重新安装 Android 10,所以我先将其删除,但现在我无法再次重新安装它,因为它不再显示在 der Android SDK 管理器中。我在哪里可以找到它?

在 SDK Platforms 下只有已安装的 SDK,而不是我可以安装的所有 SDK,这是正确的行为吗?

此外,在“SDK 更新站点”下,“已启用”下的“Android 存储库”出现错误 --> 红色标志并显示“下载清单时出现 IO 异常”消息

这是我目前在 Android Studio 中遇到的问题:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-measurement-base:[17.2.0].
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.0].
Show Details
Affected Modules: app

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


...

这是我的 build.gradle(项目):

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.android.guessit"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0-alpha10'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'

    //Firebase SDKs
    implementation 'com.google.firebase:firebase-core:17.2.0'
    implementation 'com.google.firebase:firebase-auth:19.1.0'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-ads:18.2.0'
    implementation 'com.google.firebase:firebase-perf:19.0.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'

    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"

    //Glide maybe later add code to proguard
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

    // Circle ImageView
    implementation 'de.hdodenhof:circleimageview:3.0.1'

    // CardView and GridLayout
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'

    // Facebook SDK and login
    implementation 'com.facebook.android:facebook-login:4.41.0'

    //image downloading and caching library for Android
    implementation 'com.squareup.picasso:picasso:2.71828'
}

apply plugin: 'com.google.gms.google-services'   // Google Play services Gradle plugin


我该如何解决这个问题?

【问题讨论】:

  • 修复"Also in the SDK manager the SDK 29 is displayed as partially installed although there is nothing else I can Install for this SDK".(1)在右下角,点击“显示包详细信息”(2)选择你需要的包{3)安装缺少的模块
  • 我已经这样做了,但是那里没有什么可以安装的。我已经安装了我能安装的所有东西
  • 使用它来阻止 java 版本 被更改 (misc.xml):android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } Show more of build.gradle (Project app module) Check java版本是最新的,PATHS是正确的。
  • 我更新了 JavaVersion 但仍然无法正常工作。如何检查 PATHS 是否正确?我更新了我的帖子以包含我的整个应用程序 gradle。另外我使用的是 Java 1.8 版,所以它是最新的
  • @JonGoodwin 我用更多细节更新了我的问题。我仍然面临这个问题

标签: android android-studio google-play-services


【解决方案1】:

在您的项目build.gradle 中,将google() 放在mavenLocal() 上方,如下所示:

...
allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
        maven { url 'https://maven.fabric.io/public' }

    }
}
...

【讨论】:

    【解决方案2】:

    我刚刚重新启动了我的计算机,它现在按预期工作。 SDK 更新站点下的“IO 异常”也不再显示。我认为问题在于这导致了我帖子中看到的所有错误。我还将系统设置下的 HTTP 代理更改为“自动检测代理设置”。卡巴斯基也没有以正确的方式运行,所以重启后它又可以正常工作了,这也可能是我描述的问题的解决方案。

    编辑:

    在我设法使其再次工作两天后出现错误,因此上述解决方案可能不是帮助我解决此问题的解决方案。再次遇到此问题后,我再次尝试了上述步骤,但没有任何效果,因此我使缓存无效并重新启动了 android studio,它再次为我工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 2022-06-17
      相关资源
      最近更新 更多