How does android integrate user library support library with application library?

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

I have the following doubts

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

  • what version does android do? Lower or Higher? How to see it?
  • How can I make sure that there is no v7 application conflict when any application uses my library?

case 2) Tell any application with a different version of com.android.support:appcompat-v7:25.0.1 or com.android.support:appcompat-v7:24+ , and the other compiledSDk (24 or 25) uses my library.

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

  • How does android now integrate support libraries? (Since the version of the support library ( appcompat-v7:23.0.1 ) of my library is different from the version of the compiledSDK application (25))
  • How can I make sure that there is no v7 application conflict when any application uses my library?

Someone please clear my doubts

+2
source share
1 answer
  • what version does android do? Lower or Higher? How to see it?

When creating a library, you explicitly set the dependency in build.gradle . The creator of the application does the same, which uses your library as a dependency declared in its build.gradle . If the creator explicitly declares the support library as a dependency, that version is taken (regardless of the versions declared by the dependencies). If he does not, the highest version declared by any dependency is accepted (such a support library is considered as a transitive dependency).

Example: Your library uses appcompat-v7:23.3.0 . The creator of the application is 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 the application does not use appcompat-v7 . appcompat-v7:23.3.0 will be in the application output.

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.xx , the version of appcompat-v7:24.1.0 will be in the output application.

I hope you understand.

  1. How can I make sure that there is no v7 application conflict when any application uses my library?

You cannot assure this. That is why you should always put the highest version of the support libraries in the library. I can’t even assure that the support libraries support backward compatibility. Here is an example that they do not have.

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

This is just an assumption. However, you must comply with it, but you do not need.

0
source

Source: https://habr.com/ru/post/1261386/


All Articles