android如何将自定义库的支持库与应用程序合并? [英] How does android merge the custom library's support library with that of application?

查看:72
本文介绍了android如何将自定义库的支持库与应用程序合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gradle中有一个com.android.support:appcompat-v7:23.0.1依赖的android库,compliedSDK为23

I have a android library with com.android.support:appcompat-v7:23.0.1 dependency in the gradle with compliedSDK of 23

我有以下疑问

案例1)说任何具有不同版本的应用程序com.android.support:appcompat-v7:23.3.0使用我的库.

case 1) Say any applicaion with different version com.android.support:appcompat-v7:23.3.0 uses my library.

  1. android使用哪个版本?低一或高一?我怎么看?
  2. 当任何应用使用我的库时,如何确保v7 appcompat不存在冲突?

情况2)说任何具有不同版本com.android.support:appcompat-v7:25.0.1com.android.support:appcompat-v7:24+且具有不同的splittedSDk(24或25)的应用程序都使用我的库.

case 2) Say any applicaion with different version com.android.support:appcompat-v7:25.0.1 or com.android.support:appcompat-v7:24+ and different compiledSDk(24 or 25) uses my library.

我知道The support library should not use a different version than the compileSdkVersion.

  1. Android现在如何合并支持库? (由于我的库的支持库版本(appcompat-v7:23.0.1)与应用程序的SDK(25)的版本不同,所以
  2. 当任何应用使用我的库时,如何确保v7 appcompat不存在冲突?
  1. How does the android merge the support libraries now? (Since the support library version(appcompat-v7:23.0.1) of my library is different from that of the application's compiledSDK (25) )
  2. How do i make sure there is no conflict of v7 appcompat when any app uses my library?

任何人请清除我的疑问

推荐答案

  1. android使用哪个版本?低一或高一?我怎么看?

在构建库时,将依赖项显式放置在build.gradle中.应用程序的创建者也进行了同样的操作,该应用程序将您的库用作在他的build.gradle中声明的依赖项.如果创建者将支持库明确声明为依赖项,则会采用该版本(无论依赖项声明的版本如何).如果他不这样做,则采用任何依赖项声明的最高版本(这种支持库被视为传递依赖项).

When building library you put the dependency explicitly in build.gradle. The same is done by the creator of app, that uses your library as a dependency declared in his build.gradle. If the creator explicitly declares support library as a dependency, that version is taken (regardless the versions declared by dependencies). If he does not do that, the highest version declared by any dependency is taken (such support library is regarded as a transitive dependency).

示例:您的图书馆使用了appcompat-v7:23.3.0.应用的创建者声明为appcompat-v7:25.0.1.简单的情况:采用appcompat-v7:25.0.1.

Example: Your library uses appcompat-v7:23.3.0. The creator of app declared appcompat-v7:25.0.1. Simple case: appcompat-v7:25.0.1 is taken.

示例2:.您的图书馆使用了appcompat-v7:23.3.0.应用的创建者未使用appcompat-v7. appcompat-v7:23.3.0将在输出应用程序中.

Example 2: Your library uses appcompat-v7:23.3.0. The creator of app does not use appcompat-v7. appcompat-v7:23.3.0 will be in output app.

示例3:.您的图书馆使用了appcompat-v7:23.3.0.另一个库使用appcompat-v7:24.1.0.如果创建者未明确声明appcompat-v7:xx.x.x,则版本appcompat-v7:24.1.0将出现在输出应用程序中.

Example 3: Your library uses appcompat-v7:23.3.0. Another library uses appcompat-v7:24.1.0. If the creator does not explicitly declare appcompat-v7:xx.x.x the version appcompat-v7:24.1.0 will be in output app.

希望您能理解

  1. 当任何应用使用我的库时,如何确保v7 appcompat不存在冲突?

您不能保证.这就是为什么您应该始终将最高版本的支持库放入库中的原因.我什至不能保证您的支持库保持向后兼容性. 此处是他们没有这样做的示例t.

You can't assure that. That is why you should always put the highest version of support libraries in the library. I can't even assure you the support libraries maintain backward compatibility. Here is the example that they don't.

我知道支持库不应使用与compileSdkVersion不同的版本.

I know that The support library should not use a different version than the compileSdkVersion.

那只是一个建议.但是,您应该遵守它,但不必这样做.

That is only a suggestion. However, you should conform to it, but you don't have to.

这篇关于android如何将自定义库的支持库与应用程序合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆