【问题标题】:Gradle cannot resolve version that is not requestedGradle 无法解析未请求的版本
【发布时间】:2019-05-07 05:34:18
【问题描述】:

我正在更新我的 Android 项目中的 Firebase 和 Google Play 服务。这就是我更新依赖项的方式:

//Play Services
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-measurement-base:16.0.5'
implementation 'com.google.maps.android:android-maps-utils:0.5'

//Firebase
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-config:16.1.0'
implementation 'com.onesignal:OneSignal:3.10.3'

当我构建我的项目时,它失败并出现以下错误:

Failed to resolve: com.google.android.gms:play-services-maps:17.3.4
Failed to resolve: com.google.android.gms:play-services-gcm:17.3.4
Failed to resolve: com.google.android.gms:play-services-location:17.3.4
Failed to resolve: com.google.android.gms:play-services-measurement-base:17.3.4
Failed to resolve: com.google.firebase:firebase-core:17.3.4
Failed to resolve: com.google.firebase:firebase-config:17.3.4
Failed to resolve: com.google.android.gms:play-services-basement:17.3.4
Failed to resolve: com.google.android.gms:play-services-tasks:17.3.4
Failed to resolve: com.google.firebase:firebase-common:17.3.4
Failed to resolve: com.google.firebase:firebase-iid:17.3.4
Failed to resolve: com.google.firebase:firebase-measurement-connector:17.3.4
Failed to resolve: com.google.android.gms:play-services-base:17.3.4

由于某种原因,所有库都需要 17.3.4 版本。如何让它发挥作用?

根 gradle 文件如下所示:

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        google()
        jcenter()
    }
    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'
    }
}

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

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

【问题讨论】:

  • 您确定要使用该版本的 com.google.gms:google-services 吗?具有相同版本的所有依赖项的要求只是该插件的旧版本的要求。 4.2.0 版应该不再要求您这样做了。
  • @DougStevenson 4.2.0 在附加的根 gradle 脚本中指定。是否也应该在其他地方进行配置?
  • 不,根据您在此处显示的内容,我觉得还可以。仔细检查你在做什么。也许尝试从头开始创建一个简单的项目。

标签: android firebase gradle google-play-services onesignal


【解决方案1】:

我之前遇到过 OneSignal 和依赖项的问题(例如 dependency conflict with itself)。我建议回滚到该库的早期版本,并查看它是否是最近的问题。

您是否也可以尝试将mavenCentral() 添加为存储库,因为它(至少以前)托管在那里。

【讨论】:

    【解决方案2】:

    我将 OneSignal 插件移到插件顶部,出于某种原因它有所帮助。

    apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    

    【讨论】:

      【解决方案3】:

      由于某种原因,在谷歌库中,它要求所有版本都相同,因此它采用更高版本并尝试在所有其他库上获取相同的版本。

      您需要将其他库降级并将它们都放在相同的版本中,它会起作用。

      【讨论】:

      • 这仅适用于旧版本的 google play services 插件。
      • 无论如何也没有用。当我将所有版本设置为 16.0.0 时,它开始需要 16.2.2
      • hmmm 很有趣,也许我没有升级我的 google play 服务,我只是避免使用不同的版本。
      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2020-04-18
      • 1970-01-01
      相关资源
      最近更新 更多