java - 安卓/ Gradle : how to find the good mix of Google dependencies versions?

标签 java android android-studio gradle android-gradle-plugin

由于不同 Google 依赖项的版本之间存在不良交互,我经常会出现编译错误。

典型的 gradle 文件:

implementation 'com.google.android.gms:play-services-analytics:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:17.1.1' 
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.1.0'
 implementation 'com.google.ads.mediation:facebook:4.22.1.0'

最后,项目没有像这样编译错误:

   FAILURE: Build failed with an exception.

    * What went wrong:
    Could not determine the dependencies of task ':XXX:preDebugBuild'.
    > In project 'XXX' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[1
      5.0.1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

      Dependency failing: com.google.android.gms:play-services-tasks:15.0.1 -> com.google.android.gms:play-services-basement@[
      15.0.1], but play-services-basement version was 16.0.1.

      The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
      ifact with the issue.
      -- Project 'XXX' depends onto com.google.firebase:firebase-config@16.0.0
      -- Project 'XXX' depends onto com.google.android.gms:play-services-analytics@16.0.1
      -- Project 'XXX' depends onto com.facebook.android:audience-network-sdk@4.22.1
      -- Project 'XXX' depends onto com.google.android.gms:play-services-ads@17.1.1
      -- Project 'XXX' depends onto com.google.firebase:firebase-core@16.0.1
      -- Project 'XXX' depends onto com.google.firebase:firebase-messaging@17.1.0

      For extended debugging info execute Gradle from the command line with ./gradlew --info :XXX:assembleDebug to see the
       dependency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at http
      s://github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to yo
      ur build.gradle file.

    * Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

    * Get more help at https://help.gradle.org

    BUILD FAILED in 25s

如何用可靠的方法解决此类问题? (目标是为每个库提供最新的可能版本)

最佳答案

根据你的日志文件

 Dependency failing: com.google.android.gms:play-services-tasks:15.0.1 -> com.google.android.gms:play-services-basement@[
      15.0.1], but play-services-basement version was 16.0.1.

问题是由于 Google Play Service 版本不同造成的。

要解决 android 中的此类问题,请在 gradle.properties 文件中定义一个常量版本

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# 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
COMPILE_SDK_VERSION=26
BUILD_TOOLS_VERSION=27.0.3
TARGET_SDK_VERSION=26
MIN_SDK_VERSION=17
ANDROID_SUPPORT_VERSION=26.1.0
PLAY_SERVICE_VERSION=16.0.1

要在 build.gradle(Module:app) 中使用这些常量,定义如下:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:${ANDROID_SUPPORT_VERSION as String}"
    implementation "com.google.android.gms:play-services-analytics:${PLAY_SERVICE_VERSION as String}"
    implementation "com.google.android.gms:play-services-ads:${PLAY_SERVICE_VERSION as String}"

}

同样,您可以定义其他库,例如 firebase 或其他库。

关于java - 安卓/ Gradle : how to find the good mix of Google dependencies versions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53501469/

相关文章:

AndroidX - 程序类型已经存在 : androidx. annotation.BoolRes

android-studio - 您无法移除所有正式版 APK 和 Android App Bundle

java - 列出网络上的所有设备 - Android

java - 使用最新的 Jackson Parser 库在 Android 设备上解析 JSON

java - 严格的服务器端处理(无网络浏览器交互): is Java or PHP better for this scenario?

java - 下面的语句是什么意思?

JavaFX 8 : Unstable interactive TabPane when adding new Tab

java - 扩展 Activity 时抽屉导航出现点击问题

android - android中的文件观察者

android - 如何修复android中的NoClassdefFoundError