简体   繁体   English

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

[英]What's the correct way of exposing a support library dependency in an Android library using android-gradle 3?

I develop an android library. 我开发了一个android库。 The library depends on appcompat-v7 . 该库取决于appcompat-v7 My consumers also depend on appcompat-v7 . 我的消费者也依赖于appcompat-v7 How do I most correctly expose my appcompat dependency from the libray when publishing to a maven repository? 在发布到maven存储库时,如何最正确地从libray中公开我的appcompat依赖项?

What I'm doing now 我现在在做什么

  • Listing the appcompat-v7 dependency as an implementation dependency in the library appcompat-v7依赖项列为库中的implementation依赖项
  • Using android-maven-publish to publish POM files which causes the dependency to be listed with Scope "runtime" 使用android-maven-publish发布POM文件,导致依赖项与Scope“runtime”一起列出

Yet with this setup the version preference of the library bleeds onto the consumer. 然而,通过这种设置,库的版本偏好会渗透到消费者身上。 Here is a screenshot from the consumer's project view where the library version is using v27.0.0 and the consumer is set up with 26.1.0: 以下是消费者项目视图的屏幕截图,其中库版本使用v27.0.0,消费者使用26.1.0进行设置:

在此输入图像描述

v27.0.0 takes presedence over v26.1.0, causing compiler errors (because the Fragment signature has changed). v27.0.0优先于v26.1.0,导致编译器错误(因为Fragment签名已更改)。

Is there any way to avoid this by configuring the library different, or should this be the result? 有没有办法通过配置不同的库来避免这种情况,还是应该这个结果呢? Am I wrong in assuming that different versions of the appcompat lib should be allowed in the library and in the consuming app? 假设应该允许在库和消费应用程序中使用不同版本的appcompat lib,我是错误的吗? Should I instead publish multiple binaries, each compiled against a different version of the support library to satisfy any given consumer setup? 我是否应该发布多个二进制文件,每个二进制文件针对不同版本的支持库编译,以满足任何给定的消费者设置?

Is there any way to avoid this by configuring the library different, or should this be the result? 有没有办法通过配置库不同来避免这种情况,或者这应该是结果?

Unfortunately, this the expected result. 不幸的是,这是预期的结果。 The reason of this issue is that JVM doesn't allow to have more than once class with the same package and name. 出现此问题的原因是JVM不允许具有相同包和名称的多个类。

Am I wrong in assuming that different versions of the appcompat lib should be allowed in the library and in the consuming app? 假设应该允许在库和消费应用程序中使用不同版本的appcompat lib,我是错误的吗?

As I said, this is a JVM restriction. 正如我所说,这是一个JVM限制。

Should I instead publish multiple binaries, each compiled against a different version of the support library to satisfy any given consumer setup? 我是否应该发布多个二进制文件,每个二进制文件针对不同版本的支持库编译,以满足任何给定的消费者设置?

This is the only solution that you have, even do it's very painful. 这是你拥有的唯一解决方案,即使这样做也很痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM