找不到与com.google.android.gms:play-services-base:[15.0.1,16.0.0)匹配的任何版本。

44

我正在为我的安卓应用使用Firebase,但突然间当我尝试运行应用程序时出现了一个错误。上周六它还能完美地运行。我不知道这个错误是如何发生的,也不知道如何解决它。请帮帮我。

在我的 build.gradle 文件中的依赖项

dependencies {
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.google.code.gson:gson:2.8.4'
    compile 'com.android.support:multidex:1.0.3'
    compile 'com.microsoft.azure:azure-mobile-android:3.1.0'
    compile 'com.mixpanel.android:mixpanel-android:4.8.0'
    compile 'com.firebase:firebase-client-android:2.4.0'

    compile 'com.google.firebase:firebase-core:16.0.0'
    compile 'com.google.firebase:firebase-auth:16.0.1'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-core:4.48'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'com.github.tibolte:elasticdownload:1.0.+'
    compile 'me.dm7.barcodescanner:zxing:1.8.4'
    compile 'com.google.android.gms:play-services-vision:15.0.2'
    compile 'com.android.support.constraint:constraint-layout:1.1.1'
    compile 'com.github.amlcurran.showcaseview:library:5.4.3'
    compile 'com.wang.avi:library:2.1.3'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.6.0'
    androidTestCompile 'com.android.support.test:rules:1.0.2'
}
apply plugin: 'com.google.gms.google-services'
在我的项目级别的build.gradle文件中:
dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.google.gms:google-services:4.0.0'
    }

我遇到的错误是:

找不到与com.google.android.gms:play-services-base:[15.0.1,16.0.0)匹配的任何版本。


添加 com.google.firebase:firebase-appindexing:15.0.1 - Adil
在我的情况下不起作用。 - Pradip Vadher
17个回答

35

在任何其他仓库之前,确保您的项目级build.gradle中具有google()仓库:

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

1
正如您建议的那样,我包含了google()存储库。然后出现了一个错误,并提供了更新gradle版本的链接。我更新了它之后,现在又出现了一个新的错误:无法解析:com.google.firebase:firebase-auth:16.0.0。您能帮我解决这个问题吗? - Riddhi
2
在应用级别的build.gradle中查找com.google.firebase:firebase-auth:16.0.0,并尝试将其切换到com.google.firebase:firebase-auth:16.0.1。https://firebase.google.com/docs/auth/android/start/ - mpontus

18
在 build.gradle 中添加这一行。
apply plugin: 'com.google.gms.google-services'
// Work around for onesignal-gradle-plugin compatibility
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
或者
googleServices.disableVersionCheck = true

1
我应该在哪里添加 com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true 这行代码?是在文件末尾吗? - Riddhi
1
使用相同的版本,如16.0.0:compile 'com.google.firebase:firebase-core:16.0.0' compile 'com.google.firebase:firebase-auth:16.0.1' - Gautam Surani
8
这个解决方案有效...但它会有什么副作用? - divaPrajapati09
你能分享一下在Oreo设备上崩溃的原因吗?比如有没有崩溃报告?@divaPrajapati09 - Gautam Surani
1
我觉得这很奇怪……虽然它能工作……但我担心会有什么副作用。 - ChristianoBolla
显示剩余9条评论

10

更新后我遇到了相同问题。请尝试验证您是否安装了最新的构建工具和Google存储库版本。

enter image description here

此外,请验证您正在使用的项目的build.gradle是否使用google()构建工具版本。在检查完build.gradle之后,尝试重新同步、清理和重新构建您的项目。

如果需要,尝试更新您的项目依赖项到最新版本。

buildscript {

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
    // ...
}

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

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

谢谢。但是,我找到了答案。 - Riddhi
最新的Google Play服务SDK组件不再通过屏幕截图中的SDK Manager工具发布。请改用google()存储库。 - zfromg

5
在我的情况下,我只是更新了Andorid SDK Platform-Tools,之前的版本是28.0.0,当我将其更新为28.0.1时,问题得到解决!

enter image description here


4

突然之间,在我的项目中没有任何更改的情况下,我遇到了以下错误。

错误:无法解析依赖项“:app@debug/compileClasspath”:无法解析 com.google.android.gms:play-services-location:[15.0.0, 16.0.0)。

在项目级别的build.gradle文件中:

buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://dl.bintray.com/android/android-tools'
        }
    }
dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
    }

and

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

使用上述设置我没有成功。

以下是对我有效的解决方法: 我发现问题出在onesignal上。

我向依赖项添加了排除条款:

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

然后手动添加了缺失的依赖项。 在添加了排除语句后,我得到了“Could not resolve com.google.firebase:firebase-messaging:[10.2.1, 12.1.0)”这个错误。如果您发现其他缺失的依赖关系,只需按照以下方法操作。

在模块级别的build.gradle文件中,我进行了替换。

implementation 'com.google.firebase:firebase-messaging:17.4.0' with
implementation 'com.google.firebase:firebase-messaging:10.2.1'

最终,构建成功了。我花了近5个小时在这上面。希望这能帮助到一些人。


4
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
}

apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

3

在我的情况下,一切工作正常,但突然在下一次“运行操作”中遇到了这个问题!

无论如何,通过将项目build.gradle文件中的com.google.gms:google-services更新为最新版本来解决问题,如下所示:

buildscript {

    repositories {
        jcenter()
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
    }
}

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

}

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

此外,请确保:
- 您不处于离线模式。
- 如果您在使用Http代理,请确保可以连接到Google存储库。

注意(上面的示例中):
Android Studio:3.4.2
compileSdkVersion 28
targetSdkVersion 28


2

构建 -> 清理项目

在我的特殊情况下 (使用 gms:v15.0.1firebase:v16.0.1),执行此操作已足够。


2

这是对我有效的方法。在项目级别的Gradle文件中,请使用以下顺序:

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

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url "https://jitpack.io"
        }
        jcenter()
    }
}

2

我用这个 build.gradle [项目] 解决了这个问题。

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://dl.bintray.com/android/android-tools'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

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