无法解决依赖项':app@debug/compileClasspath':无法解决com.google.android.gms:play-services-basement:[15.0.0,16.0.0)。

19

我遇到了这个错误: 这是我的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
}

我已经检查了其他解决方案,大多数建议在项目的build.gradle中添加

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

我已经尝试过这个方法,但我仍然收到相同的错误信息。

我正在使用Android Studio 3.0。 我还尝试过将google()添加到build.gradle中(另一个建议)。


我个人也遇到了同样的问题,有一次我成功捕获了一行代码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。因此,现在谷歌仓库可能出现了问题的几率很大。 - egorikem
2
@AnkushRishi 我在另一个本地账户中安装了Android Studio并且它可以正常工作,可能你需要重新安装Android Studio和SDks。 - Anirudh Bagri
1
我认为在我的情况下不需要重新安装Android Studio,只需执行“清理项目”和“重建项目”即可解决问题。 - Husnain Qasim
@AnirudhBagri:请检查我的答案。 - Alireza Noorali
文件->清除缓存并重启 对我有用。 - androidGeek
13个回答

8

选项1:

按照以下步骤解决问题。

项目级别的build.gradle

使用

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

替代

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

选项 2:

项目级别的 build.gradle

google() 仓库应该是第一优先级。

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

选项 3:

按照以下步骤解决问题。

步骤 1:

项目级别的 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
}

步骤2:

应用程序级别的build.gradle文件

我已经更新了One Signal版本。

使用方法:

implementation 'com.onesignal:OneSignal:3.11.1'

代替

implementation 'com.onesignal:OneSignal:3.10.9' 

2
我简直不敢相信,但选项1显然为我解决了这个问题。 - Simon Schubert

6

前往文件→其他设置→默认设置→构建、执行、部署→构建工具→Gradle→取消选中 离线工作 选项。


6
这个回答(已经写了好几十次)有帮助过任何人吗?我不认为如此,这个问题通常都是与依赖项设置不正确或Google资源库出现混乱有关。那么为什么每次都要发布这个无用的“提示”呢? - egorikem
@GeorgySavatkov:是的,Georgy,它解决了我相同的问题。 - Alireza Noorali
它对我没用!我尝试了论坛中所有可能的建议 :( - Anirudh Bagri
3
如果仍然没有效果,请检查您的互联网连接。 - Daksh Agrawal
1
@DakshAgrawal 如果他可以连接到 https://stackoverflow.com/ 来提问,为什么他的互联网连接会有问题呢? - Muhammad Asyraf
显示剩余2条评论

6

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

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

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

在应用程序文件夹中,然后手动添加任何其他缺失的依赖项,例如:

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

问题在于OneSignal SDK包含与我在应用程序中使用的最新版本的gms和firebase不同版本的Google Play服务依赖项。

因此,我建议您找出在项目中添加了使用google play服务的依赖项,并对其使用exclude子句。如果系统连接到互联网,则gradle应该能够构建。

希望这有所帮助。


4

我使用了VPN进行网络连接。关闭VPN后,问题解决了。


2

使用VPN解决了我的问题。


2

我曾经遇到过这个问题,并且之前使用了代理。后来我发现我的代理已经不起作用了,于是我去设置中将代理配置更改为“自动”,但仍然显示相同的错误。

最终我发现代理也被自动设置为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服务。


0

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

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


0
如果您突然遇到了这个问题,可能是在生成apk时出现了损坏。这种情况很少发生。
解决方案:重新构建任务。 您可以在此图像中查看

0

将代码库更新到最新版本后,问题得到了解决。

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

0
打开顶级 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服务和Gradle到最新版本即可。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接