android - 两个依赖使用相同的库但版本不同

标签 android gradle android-gradle-plugin build.gradle

我似乎有 Picasso 库 2.4.0,但 twitter 也使用该库的 2.3.2 版本。我的问题是... 2.3.2 库会与较新版本一起下载吗?或者只是下载了 2.4.0 并由 Twitter 使用?我应该排除 2.3.2 版本而 twitter 会自动使用 2.4.0 吗?这样安全吗?较新的版本可能与 twitter 库不兼容,不是吗?

我很困惑在这种情况下我应该如何进行。我应该排除哪个库(如果我可以排除的话)。

gradle -q app:dependencyInsight --dependency picasso --configuration compile

com.squareup.picasso:picasso:2.4.0 (conflict resolution)
\--- compile

com.squareup.picasso:picasso:2.3.2 -> 2.4.0
\--- com.twitter.sdk.android:tweet-ui:1.1.0
     +--- compile
     \--- com.twitter.sdk.android:twitter:1.1.1
          \--- compile

(*) - dependencies omitted (listed previously)

最佳答案

根据Gradle docs :

Gradle offers the following conflict resolution strategies:

Newest: The newest version of the dependency is used. This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible.

Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. See ResolutionStrategy for details on how to explicitly choose a particular version.

因此 Gradle 将使用 Picasso 2.4.0 管理依赖项。

这会是个问题吗?可能吧。如果 Twitter 使用的方法和/或签名已从 2.3.x 更改为 2.4,您将遇到问题。如果它们彼此向后兼容,您将不会遇到任何问题。

我现在确实看到了 Twitter SDK实际上已经将他们的 Picasso 库升级到 2.5.2(最新)。如果您的项目导入 Picasso,那么您也可以更新它(并且可能应该)。如果它是另一个模块中的依赖项,那么您也可以更新该模块。

另一种选择是将 Picasso 降级到 2.3.2 或使用 ResolutionStrategy使用较低版本。除非你必须这样做,否则我不会推荐这个。

关于android - 两个依赖使用相同的库但版本不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41125833/

相关文章:

Gradle错误,创建目录失败

android - getZoom 和 getVisibleBounds 方法永远不会在 @mapbox/react-native-mapbox-gl Android 中解析

android - 在 Android 的按钮内居中大文本不起作用

android - Android 6.0+:我的应用禁用了地理位置定位(即使在手机设置和 list 中启用了地理位置定位)

android - GoogleSource的Android NDK的Eigen库

android - 我的项目中有不同的 Gradle 版本? (gradle.xml 与 build.gradle)

android - Gradle(android实验插件)忽略一个项目依赖

android - Gallery针对不同的Android版本为Intent.ACTION_GET_CONTENT返回不同的媒体文件URI

android - 如何将溢出菜单添加到工具栏?

android - 如何使用Android Studio重命名程序包?