【问题标题】:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-basement:[15.0.0,16.0.0)无法解析“:app@debug/compileClasspath”的依赖关系:无法解析 com.google.android.gms:play-services-basement:[15.0.0,16.0.0)
【发布时间】:2018-06-12 16:53:56
【问题描述】:

我收到此错误: 这是我的 build.gradle(Module:app)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.mycompany.myapp"
        minSdkVersion 19
        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'
        }
    }
    dataBinding.enabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.firebase:firebase-core:15.0.0'
    compileOnly "org.projectlombok:lombok:1.16.20"
    annotationProcessor 'org.projectlombok:lombok:1.16.20'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.0'
    implementation 'com.google.android.gms:play-services-location:15.0.0'
    implementation 'com.google.android.gms:play-services-places:15.0.0'
    implementation 'com.paytm.pgsdk:pgsdk:1.0.8'
    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'
    compile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
}

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

这是我的 build.gradle(Project: myApp)

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'io.fabric.tools:gradle:1.25.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

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

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

我检查了其他解决方案,大多数都建议添加

maven { url "https://maven.google.com" }

到 build.gradle 项目。我已经尝试过了,但我仍然遇到同样的错误。

我使用的是 android studio 3.0。 我也尝试添加 google() 而不是 maven(另一个建议)

【问题讨论】:

  • 我个人也有同样的问题,有一次我能抓住一条线Caused by: org.gradle.internal.resource.transport.http.HttpErrorStatusCodeException: Could not HEAD 'https://jcenter.bintray.com/com/google/firebase/firebase-messaging/15.0.2/firebase-messaging-15.0.2.pom' CODE 500。所以现在谷歌回购被破坏的可能性很大
  • @AnkushRishi 我在另一个本地帐户的android studio中安装了android studio,它可以工作,可能你需要重新安装android studio和sdks
  • 我认为不需要重新安装 android studio,我只需 Clean Project 然后 Rebuild Project 就可以了。
  • @AnirudhBagri:请检查我的答案。
  • Files->使缓存无效并重新启动对我有用。

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


【解决方案1】:

选项 1:

按照以下说明解决。

项目级 build.gradle

使用

maven { url "https://www.jitpack.io" }

而不是

maven { url "https://jitpack.io" }

选项 2:

项目级 build.gradle

google() 存储库应该是第一优先

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

选项 3:

按照以下步骤解决。

第一步:

项目级 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.google.gms:google-services:4.2.0' // google-services plugin
        classpath 'com.android.tools.build:gradle:3.4.2'

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

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        maven { url "https://jitpack.io" } // For Ucrop
        maven { url "https://maven.google.com" } // Google's Maven repository - FCM
        maven {
            url 'https://dl.bintray.com/azeesoft/maven'
        }
        google()
        jcenter()
        mavenCentral()
    }
}

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

第二步:

应用级 build.gradle

我已更新 One Signal 版本。

使用

implementation 'com.onesignal:OneSignal:3.11.1'

而不是

implementation 'com.onesignal:OneSignal:3.10.9' 

【讨论】:

  • 我不敢相信,但选项 1 显然为我解决了这个问题。
【解决方案2】:

转到文件→其他设置→默认设置→构建、执行、部署→构建工具→Gradle→取消选中Offline work选项。

【讨论】:

  • 这个答案(写了几十遍)对任何人都有帮助吗?我不这么认为,这个问题总是与错误设置依赖项或谷歌回购被搞砸有关。那么为什么每次都发布这个无用的“提示”呢?
  • @GeorgySavatkov:是的,Georgy,它解决了我同样的问题。
  • 它对我不起作用!我尝试了论坛中所有可能的建议:(
  • 如果仍然无法正常工作,请检查您的互联网连接。
  • @DakshAgrawal 如果他可以连接到stackoverflow.com 来提问为什么他的互联网连接会是问题
【解决方案3】:

我在我的 Android 应用程序中使用 OneSignal 处理推送通知时遇到了同样的问题。

解决方案是在其依赖中添加排除子句:

implementation ('com.onesignal:OneSignal:3.8.3'){
    exclude group: 'com.google.android.gms'
}

在 app 文件夹中,然后手动添加任何其他缺少的依赖项,例如:

implementation 'com.google.android.gms:play-services-appinvite:16.1.0'

问题是 OneSignal SDK 包含的 Google Play Service 依赖项与我在应用中使用的最新版本的 gms 和 firesbase 版本不同。

所以我建议你找出你添加的一个依赖项,它在项目中使用 google play 服务,并在其上使用 exclude 子句。虽然如果您的系统连接到互联网,您的 gradle 应该构建。

希望这有帮助。

【讨论】:

    【解决方案4】:

    我使用 VPN 连接互联网。我关闭了 VPN,它对我有用。

    【讨论】:

      【解决方案5】:

      使用 VPN 解决了​​我的问题。

      【讨论】:

        【解决方案6】:

        我遇到了这个问题,我之前使用过代理。我发现我的代理不再工作,所以我去设置并将代理配置更改为自动,但仍然显示相同的错误。

        我终于发现代理也自动设置为 gradle,但是当我禁用它时,它并没有从我的 gradle 配置中删除。所以我去了C:Users/User/.gradle/gradle.properties,在那个文件中有这样的东西:

        ## For more details on how to configure your build environment visit
        # http://www.gradle.org/docs/current/userguide/build_environment.html
        #enter code here
        # Specifies the JVM arguments used for the daemon process.
        # The setting is particularly useful for tweaking memory settings.
        # Default value: -Xmx1024m -XX:MaxPermSize=256m
        # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
        #
        # When configured, Gradle will run in incubating parallel mode.
        # This option should only be used with decoupled projects. More details, visit
        # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
        # org.gradle.parallel=true
        #Sat Aug 31 18:23:27 IRDT 2019
        systemProp.https.proxyPort=8118
        systemProp.http.proxyHost=fodev.org
        systemProp.https.proxyHost=fodev.org
        systemProp.http.proxyPort=8118
        

        所以我刚刚编辑了这个文件并注释了最后 4 行,它解决了我的问题。

        我也在使用 VPN 服务。

        【讨论】:

          【解决方案7】:

          我的问题是...
          我可以运行该项目......但突然出现了这个错误。
          经过几次尝试“重试”解决方案但没有解决。

          最后浪费了几分钟。我尝试清洁项目。并重建。 Tadaaaa 它工作。
          我不知道这是否会帮助任何人,但它解决了我的问题。希望它能解决你的问题。

          【讨论】:

            【解决方案8】:

            打开顶层 build.gradle 文件并添加 google-services:

            buildscript {
                repositories {
                    google()
                    jcenter()
                }
                dependencies {
                    classpath 'com.android.tools.build:gradle:3.6.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
                }
            }
            

            如果您已经添加了它,只需将 google-service 和 gradle 更新到最新版本

            【讨论】:

              【解决方案9】:

              如果你突然出现这个问题,可能是在生成 apk 时损坏了。这种情况很少发生

              解决方案:重建任务

              you can see it in this image

              【讨论】:

                【解决方案10】:

                将存储库更新到最新版本为我解决了这个问题。

                implementation 'com.google.android.gms:play-services-ads-identifier:17.0.1'
                

                【讨论】:

                  【解决方案11】:

                  就我而言,我只是将我的项目级别构建 Gradle 和其他依赖项更改为最新版本,并将应用级别构建 gradle 中的 Google Maps 依赖项更改为 10.0.0。

                  【讨论】:

                    【解决方案12】:

                    Just Build → Clean Project 为我工作

                    【讨论】:

                      【解决方案13】:

                      您是否尝试在依赖项中添加此内容:

                      implementation 'com.google.android.gms:play-services-basement:15.0.0'
                      

                      【讨论】:

                      • 尝试使缓存失效/重启
                      • @JoshuaStephen 我试过无效缓存/重启。还是不行
                      猜你喜欢
                      • 2018-12-15
                      • 1970-01-01
                      • 1970-01-01
                      • 2018-08-26
                      • 1970-01-01
                      • 1970-01-01
                      • 2022-08-15
                      • 1970-01-01
                      • 2018-04-10
                      相关资源
                      最近更新 更多