问题描述
我有一堆第三方库,我包含在我的基础应用程序中.我无法控制那些 3rd 方模块包含的支持库.这使得在我的应用程序中很难拥有相同版本的 android 支持库.
当我可以从每个依赖项中排除某些库时,我知道使用 gradle:
但是,有大量的支持库,并且将它们全部排除在我的每个 3rd 方库中似乎有点矫枉过正.
有没有更好的办法?
阅读这篇博文:
这当然是可能的.在您的项目 build.gradle 文件(顶级 build.gradle 文件)中添加以下代码块:
以下代码确保所有依赖项的com.android.support"依赖项版本都等于 $supportlib_version.'com.google.android.gms' 框架也是如此.
确保在您的模块的 build.gradle 文件中,您也将这些版本用于您的依赖项.例如:
在 中阅读有关强制某个依赖版本的更多信息Gradle 官方文档.
更新Google 已经分离了库版本.因此,强制高于 15.0.0 的特定版本可能不起作用.相反,您可以允许有限范围的版本.下面的示例允许任何高于 15.0.0 但低于 16 的版本.
I have a bunch of third party libs that I include in my base application. I cannot control the support library those 3rd party modules include. This makes it hard to have the same version of the android support library in my application.
I know using gradle when I can exclude certain libraries from each dependency:
However there are a ton of support libraries and excluding them all for each one of my 3rd party libraries seems like overkill.
Is there a better way?
Reading this blog post: https://www.devsbedevin.net/android-understanding-gradle-dependencies-and-resolving-conflicts/
It suggests:
However when using that I still get a warning in Android Studio in my gradle file that there are multiple versions of the support library detected.
What do I do if my dependencies depend on different versions of the support library? In either case above I would be forcing the 3rd party libraries to use a specific version of the support library that they were not build with. Which version am I supposed to use? Latest support library? Min support library of all 3rd party dependencies?
Here is a minimal gradle file example showing pulling in 3rd party dependencies that each depend on their own version of the support library.
Android studio gives the following warning:
This is certainly possible. In your projects build.gradle file (the top level build.gradle file) add the following code block:
The following code ensures that the 'com.android.support' dependency version will be equal to $supportlib_version for all dependencies. The same for the 'com.google.android.gms' framework.
Make sure that in your module's build.gradle file you also use these versions for your dependencies. E.g.:
Read more about forcing a certain dependency version in the Official Gradle documentation.
Update Google has decoupled library versions. Therefore, forcing a specific version above 15.0.0 may not work. Instead, you can allow a limited range of versions. The example below allows any version higher than 15.0.0 but lower than 16.
这篇关于如何使用 gradle 为 3rd 方部门管理不同的支持库版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!