无法解决Google Play服务版本15.0.2。

3

当我想要安装Google Play服务15.0.2(因为15.0.0会出现dexing错误,我不知道原因),我在Gradle中遇到了以下错误:

Failed to resolve: com.google.android.gms:play-services-location:15.0.2
Install Repository and sync project
Open File
Show in Project Structure dialog


Failed to resolve: com.google.android.gms:play-services-basement:15.0.2
Install Repository and sync project
Open File
Show in Project Structure dialog


Failed to resolve: com.google.android.gms:play-services-tasks:15.0.2
Install Repository and sync project
Open File
Show in Project Structure dialog

但是我从未在任何build.gradle文件中添加这些依赖项。 如果我想通过安装按钮安装,我会遇到错误: 找不到依赖关系。
这是我的build.gradle文件:
apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION             = 25
def DEFAULT_BUILD_TOOLS_VERSION             = "25.0.2"
def DEFAULT_TARGET_SDK_VERSION              = 25
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "15.0.2"

android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? 
project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
buildToolsVersion project.hasProperty('buildToolsVersion') ? 
project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 
project.hasProperty('buildToolsVetargetSdkVersionrsion') ? 
project.buildToolsVersion : DEFAULT_TARGET_SDK_VERSION
    versionCode 1
    versionName "1.0"
}
}

repositories {
mavenCentral()
}

dependencies {
    def googlePlayServicesVersion = 
project.hasProperty('googlePlayServicesVersion') ? 
project.googlePlayServicesVersion : DEFAULT_GOOGLE_PLAY_SERVICES_VERSION

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.facebook.react:react-native:+'
    compile "com.google.firebase:firebase-core:$googlePlayServicesVersion"
    compile "com.google.firebase:firebase-messaging:$googlePlayServicesVersion"
    compile 'me.leolin:ShortcutBadger:1.1.17@aar'
}

编辑: 我成功解决了我的问题。 实际上,在我的父级build.gradle中有一个multidex脚本,它强制更新了所有的com.gms.google到15.0.2,但正如你所说,谷歌游戏服务没有15.0.2。 我只需删除此脚本即可解决问题。


不要导入所有的谷歌服务,因为方法数量过多会导致 dex 错误,我建议只实现你在应用中需要使用的那些服务。 - Gastón Saillén
1
请查看此博客文章:https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html - Bob Snyder
你找到解决方案了吗,@Psyycker? - Levi Moreira
我终于解决了我的问题,请查看编辑以了解我是如何解决的。ADM的答案很有帮助,让我明白为什么无法下载Google Play服务15.0.2。 - Psyycker
1个回答

2
Firebase库现在具有独立的版本,而不是它们之前共享的相同版本。请参见这里。目前这样做是可行的,但未来可能会有所不同。
implementation "com.google.firebase:firebase-core:$googlePlayServicesVersion"
implementation "com.google.firebase:firebase-messaging:$googlePlayServicesVersion"

更重要的是,Firebase库不再与Google Play服务库具有相同的版本号,例如位置等Play服务库没有15.0.2版本,详情请参见此处,最新版本为15.0.0。

我的建议是逐个定义每个库。

要解决您的问题,请更改以下内容:

def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION    = "15.0.0"

并且这个:

implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-messaging:15.0.2"

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