Possible effects of mixing dependencies versions - android

Recently I wanted to update my app's dependencies, as I saw new version of com.android.support:appcompat-v7 library came up (27.0.0). After incrementing this lib version, Android Studio underlines this library and shows a popup with error message:
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 27.0.0, 25.2.0. Examples include
com.android.support:animated-vector-drawable:27.0.0 and
com.android.support:support-v13:25.2.0
I've run gradlew app:dependencies command and saw other dependency which uses android support lib but it's older version - 25.2.0. My question is: what should I do? I assume I have to downgrade android support lib version as otherwise I may see No Method Found or No Class Found errors, am I right? Is it possible to include both of these versions somehow, that the library causing conflicts will be still able to use older version?
Thanks for help!

As you wrote already, one way is to downgrade to the lowest version. But I think that as long as you are not using that specific methods that the library with older dependency is using, you should be fine. But for the sake of safety, you should have all the dependecies of the same version

Related

Which com.google.android.gms:play-services-ads version is compatible with com.android.support:appcompat-v7:27.1.1?

No duplicate:
In my question I've already linked an answer similar to the supposed duplicate and explained, why I'm not looking for such an answer.
Android Studio 3.2.1 automatically included
implementation 'com.android.support:appcompat-v7:27.1.1'
for my new app. I manually included
implementation 'com.google.android.gms:play-services-ads:17.1.1'
following the official guide.
The official guide from google seems to be outdated, as Android Studio immediately suggests using version 17.1.3 instead.
In both cases however there is a red line under appcompat-v7 and a tooltip warning me that:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0.
I do get the general problem here, play-services-ads transitively depends on an old version of some support library. This answer suggests to simply include the offending libraries manually in the correct version.
However, I don't like this solution for two reasons:
I simply don't want to deal with problems like this. There should be compatible versions available for the google libraries.
At some point in the future I might have forgotten why I included all these libraries I don't even know what they do. I might want to update the appcompat and play-services-ads dependencies without thinking about all this again.
Is version 17.1.3 the most recent version of play-services-ads as of now? Does that mean that play-services-ads is generally lagging behind? If so, I would prefer to downgrade appcompat-v7 instead of including some library versions manually.
What would be the correct version of appcomat-v7 for play-services-ads version 17.1.3? Or maybe more generally asked: Which are the most recent versions of appcompat-v7 and play-services-ads that work together hassle free?
26.1.0 is the correct appcompat-v7 version for play-services-ads 17.1.*
implementation 'com.android.support:appcompat-v7:26.1.0'
This also requires compileSdkVersion and targetSdkVersion to be set to 26.

Finding which dependency includes what

I currently have a warning in my build.gradle about support libraries not using the same version.
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 27.0.1, 23.4.0. Examples include
com.android.support:animated-vector-drawable:27.0.1 and
com.android.support:cardview-v7:23.4.0
I do not actually include cardview-v7:23.4.0 and I'm trying to find out which library I'm using does.
What's the easiest way to see this?
And there is also a good way to see method counts of the libraries too?
Thanks.
You can plug in the dependency here and find out what dependencies the dependency has from the pom or read my post here its more better to call them transitive dependencies

How does Gradle choose between more than 1 versions of the same library in a gradle tree?

Let say I have added Facebook and Twitter dependencies in my app.
com.facebook.android:facebook-android-sdk:4.22.1
com.twitter.sdk.android:twitter:2.1.0
When i look at Gradle tree, They come up with bunch of other transitive dependencies.
Now If Facebook uses com.android.support:support-annotations:24.1.1 and twitter uses com.android.support:support-annotations:25.0.3
Then which version gradle will use.
In gradle tree, It shows -> in front of older version of dependency. I learnt that this means gradle will use the newer version, and will not use the older version.
But this can be a problem, because some libraries are meant to run on the specific versions, and i have faced this problem.
In one of article i found out how npm manages these dependencies conflicts, but i am still unsure how gradle will manage between different version of same library.
You can't have different versions of the same library inside an apk.
As you mentioned, by default, Gradle puts the newest one to the build. If you want to specify a concrete version of the library that should be used in your project, you can add a direct compile (or implementation / api for Android Gradle Plugin v3+) statement with a required version to get one.
Also, you can force version using a special syntax, but it can lead to some problems later. You can find more information about version conflicts resolution in this post

Android support library incompatiblity

I have a jcenter library ToggleButtons I develop that I import into my app. After switching to support 26.1.0 in my app, I receive this error:
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 26.1.0, 25.3.1
ToggleButtons:
com.android.support:cardview-v7:25.3.1
Main app:
com.android.support:design:26.1.0
I'm using other libraries such as Glide that reference even earlier versions of the support library (I haven't upgraded to 4 yet), but those don't have an issue. Have I designed the library improperly somehow?
This was always a recommendation, now they're making it generate errors.
You absolutely can't run an app with both versions, because that would cause duplicated classes errors. That means you must pick one of those manually now, while previously gradle would automatically choose one for you.
I'd suggest you use the higher number, since doing the opposite risks missing new features/assets that either library or app really depends on.
You can add this between your android and dependencies blocks in your application / library module's build.gradle for each conflict you must manually solve:
def supportLibraryVersion = '26.0.1'
configurations.all {
resolutionStrategy {
force "com.android.support:cardview-v7:$supportLibraryVersion"
}
}
I guess you get the idea of how it works.
Edit:
As noted by #eugen-pechanec the best practice is having all your support libraries with same version throughout all your projects modules. Also, it's best to use the same numbers on build tools (in module's build.gradle, inside android block).
Here's what your app depends on:
+ design:26.1.0
+ appcompat-v7:26.1.0
+ support-v4:26.1.0
+ recyclerview-v7:26.1.0
+ support-v4:26.1.0
Here's what the library depends on:
+ cardview-v7:25.3.1 (i.e. at least 25.3.1)
Here's what it means:
Card view library doesn't have any (runtime) dependency on other support libraries so technically in this case it's safe to use different versions. However this may change at any time.
More importantly your own code does not define cardview-v7 as a dependency so there's no way for gradle to know it should pull updated version as well.
The easiest fix then is just defining the dependency in your build.gradle:
def supportLibraryVersion = '26.0.1'
compile "com.android.support:cardview-v7:$supportLibraryVersion"
No force, nothing special. Upgrading a dependency is not a problem. Only downgrading is.
I still don't understand why Glide doesn't throw this error when they're using support 25.
As hinted above, Glide uses at least support-v4 25.x.x. And because a newer version of support-v4 is already requested by your own module, the dependency gets silently upgraded.

different version number gradle file

My compiledsdkversion is 23. My Android support library has a 24.0.0-alpha1designation at the end of the string which declares it on my gradle app file. Gradle is compiling with errors stating that the support library should not use a different version than the compiledsdkversion.Any ideas on how to get rid of this error. I don't know how to update the compiledsdkversion.
You should use the latest stable version of the Support Library, which is currently 23.2.1 as per the release notes.

Categories

Resources