How does android merge the custom library's support library with that of application? [duplicate]

假装没事ソ 提交于 2020-01-13 05:51:26

问题


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

I have following doubts

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

  1. which version does the android take? Lower one or Higher one? How do i see it?
  2. How do i make sure there is no conflict of v7 appcompat when any app uses my library?

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.

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

  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?

Anyone Please clear my doubts


回答1:


  1. which version does the android take? Lower one or Higher one? How do i see it?

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).

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.

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.

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.

Hope you understand.

  1. How do i make sure there is no conflict of v7 appcompat when any app uses my library?

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.

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.



来源:https://stackoverflow.com/questions/40859766/how-does-android-merge-the-custom-librarys-support-library-with-that-of-applica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!