android - 使用 android-gradle 3 在 Android 库中公开支持库依赖项的正确方法是什么?

标签 android maven gradle dependency-management android-gradle-3.0

我开发了一个 android 库。该库依赖于 appcompat-v7。我的消费者也依赖于 appcompat-v7。发布到 maven 存储库时,如何最正确地从 libray 公开我的 appcompat 依赖项?

我现在在做什么

  • appcompat-v7 依赖项列为库中的 implementation 依赖项
  • 使用android-maven-publish发布 POM 文件,导致依赖项在范围“运行时”中列出

然而,通过这种设置,库的版本偏好会影响到消费者。这是消费者项目 View 的屏幕截图,其中库版本使用 v27.0.0,消费者设置为 26.1.0:

enter image description here

v27.0.0 优先于 v26.1.0,导致编译器错误(因为 Fragment 签名已更改)。

有什么方法可以通过配置不同的库来避免这种情况,或者应该这就是结果吗?我假设库和消费应用程序中应该允许不同版本的 appcompat lib 是错误的吗?我是否应该发布多个二进制文件,每个二进制文件针对不同版本的支持库进行编译以满足任何给定的消费者设置?

最佳答案

Is there any way to avoid this by configuring the library different, or should this be the result?

不幸的是,这是预期的结果。这个问题的原因是 JVM 不允许有多个具有相同包和名称的类。

Am I wrong in assuming that different versions of the appcompat lib should be allowed in the library and in the consuming app?

正如我所说,这是一个 JVM 限制。

Should I instead publish multiple binaries, each compiled against a different version of the support library to satisfy any given consumer setup?

这是您唯一的解决方案,即使这样做也很痛苦。

关于android - 使用 android-gradle 3 在 Android 库中公开支持库依赖项的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47024317/

相关文章:

android - 如何使用android studio构建ndk项目?

android - 替换公钥(Base64)后商品标题和描述不显示 Android 应用内购买

android - 如何禁用 snackbar 的滑动关闭行为

android - Android 中 fragment 的行为

maven - 如何在 IntelliJ 14 中向 pom.xml 添加依赖项

maven - 在 DockerFile 中动态获取 JAR 文件名

java - 将非开源依赖项与 Maven 捆绑在一起

android - 如何抑制与项目无关的android gradle依赖项警告

android - 错误重复输入:Android Studio中的android/support/v4/view/GestureDetectorCompat $ GestureDetectorCompatImpl.class

testing - 什么限制了 Gradle 构建中的活跃工作人员数量?