Android / Gradle: как найти хорошее сочетание версий зависимостей Google? - PullRequest
0 голосов
/ 27 ноября 2018

У меня часто возникают ошибки компиляции из-за версий различных зависимостей 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

Как решить эту проблему с помощью надежной методологии?(с целью иметь последнюю возможную версию для каждой библиотеки)

Ответы [ 2 ]

0 голосов
/ 27 ноября 2018

Я не думаю, что есть прямой ответ на ваш вопрос.

Я бы порекомендовал использовать com.google.firebase:firebase-ads:17.1.0, поскольку он также должен включать как play-services-analytics, так и play-services-ads, которые затем можно удалить.,И затем каждые две недели следите за релизными версиями ваших библиотек.

Да, я знаю, это, вероятно, не тот ответ, который вы искали, но в долгосрочной перспективе,это даст вам меньше головной боли.


Если этого недостаточно, чтобы убедить вас, есть другой способ сократить время, необходимое для обновления версий, используя + в несовершеннолетнемномер версии (например, 16.0.+ вместо 16.0.0).

ПРЕДУПРЕЖДЕНИЕ: Автоматическое увеличение номеров версий может привести к проблемам (то есть: разрешены разные версиив вашем CI и вашем локальном компьютере непредвиденные несовместимости, невоспроизводимые сборки и т. д.

И некоторые различия версий в сервисах Firebase и Play на самом деле серьезные изменения (то есть: firebase-core:16.0.4 и firebase-ads:17.1.0), поэтому удобные + на вспомогательной версии не будут работатьдля всех случаев, и вам нужно будет поставить + на весь номер версии, что не разрешено.

0 голосов
/ 27 ноября 2018

Согласно вашему файлу журнала

 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 определите постоянную версию в * 1007.* file

# 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 или другие.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...