2

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

Arnold Laishram
  • 1,801
  • 2
  • 18
  • 25
  • look from here http://stackoverflow.com/questions/37191869/how-to-avoid-dex-64k-limit-by-importing-the-right-library/39809125#39809125 – Saveen Nov 29 '16 at 07:22
  • Didn't help. I tried using compiledSDK in the application as 25. and compiled my library (compiledSDK of 23). It works. But my basic question is how does the android merge the support library of my library and that of the application. – Arnold Laishram Nov 29 '16 at 07:34

1 Answers1

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

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • Thanks Zagorski, Cleared few doubts. Here is one more, In your example 3, what if the compiledSDK of application is 23 with appcompat-v7:23.3.0 and and that of the library is 24 with appcompat-v7:24+ . Which all support libraries does the android take? if it takes appcompat-v7:24+, does it mean that it doesn't matter what compiledSDK is the application using? Or will the compiledSDK change itself for application to 24 since the library has compiledSDK of 24? – Arnold Laishram Nov 29 '16 at 09:20
  • I've just compiled the project with `compileSdkVersion 23` and `appcompat-v7:25.0.0`. Inside output `AndroidManifest.xml` the is `platformBuildVersionCode="23"`. So it works and will compile. Checked `appcompat` sources packed into .apk and indeed their version is 25. And of course I get the warning `This support library should not use a different version (25) than the targetSdkVersion (23)` - an advice to properly maintain dependency and compilation versions. – R. Zagórski Nov 29 '16 at 10:05