Android Support Repo 46.0.0 with Android Studio 2.3

Android Support Repo 46.0.0 with Android Studio 2.3


What's the problem

Some libraries depend on version "X or newer" of Android support libraries so Gradle dependency resolution grabs whatever is the newest available ignoring you actually have a precise version specified in your dependencies block.

This is not what you want. You want all support libraries with same version and major version has to match compile SDK version.

What's the solution

Fortunately you can force a specific support library version.

Put this at the end of your app module build.gradle:

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
// Skip multidex because it follows a different versioning pattern.
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}
}

Of course replace the version with whatever it is you're using.

Version values for support libraries in dependecies block are now irrelevant.

If you have doubts

This is a well documented method and it's working.

What can you do to help

Find the libraries which depend on a range of support library versions

gradlew dependencies --configuration compile -p <module name> | grep ,

and let the authors of said libraries know they should transitively depend on the oldest support libs their library can do with.

This aims to avoid the issue altogether.

Support library version


If I try anything lower than 20 it says: library should not use a lower version then targetSdk version.

That is because you set your targetSdkVersion to something higher than 19. If you did so intentionally, fine. If you did not do so intentionally, consider dropping it back to 19 for now, and use compile 'com.android.support:support-v4:19.1.0' (if you are using the backport of fragments) or compile 'com.android.support:support-v13:19.1.0' (if you are not using the backport of fragments).

If I use compile 'com.android.support:support-v4:20' I get: Failed to find: com.android.support:support-v4:20

That is because the Android Support package uses X.Y.Z semantic versioning, as do most artifacts in repositories. 20 does not match the X.Y.Z pattern.

If I use compile 'com.android.support:support-v7:20.0.+' I get: Avoid using + in version numbers, can lead to unpredictable and unrepeatable builds.

That is merely a warning. If you are using version control for your project files, and you feel that it is important to be able to check out some earlier version of your code and be able to reproduce that build, then using the + notation is not a good idea. OTOH, if being able to reproduce historical builds is not essential, using the + wildcard, as you are doing, ensures that you get updates automatically. Having the + in the third position (Z in X.Y.Z) means that you will automatically get patchlevel updates.

where can I find up-to-date, ready to use, version numbers that Do work?

On your hard drive, in $ANDROID_SDK/opt/extras/android/m2repository/com/android/support/$LIBRARY/, where $ANDROID_SDK is wherever you installed the Android SDK and $LIBRARY is whichever Android Support package library you are interested in (e.g., support-v13).

Android support library incompatiblity

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

How to Solve Mix version Error in Build.gradle android Studio?

There are 2 ways to fix it

1) Hover your mouse on top of the error for some time and it will show you what libraries have mixed versions , just add those libraries in your project .

In your case add

implementation 'com.android.support:support-media-compat:28.0.0'

It may show other libraries after adding this . Add those libaries too . All support library packages can be found over here

2) Add this at the end of app level build.gradle

configurations.all {
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "28.0.0"
}
}
}
}

Credit to Eugen Pechanec

Android Studio 2.3 Beta 1 + Support 25.1.0 = Preview broken

Everything works now.

  1. I upgraded today to the newest Android Studio: 2.3 Beta 3
  2. I was prompted to update to the latest com.android.tools.build:gradle:2.3.0-beta3

Restarted, invalidated, rebuilt; everything is finally rendering perfectly in the preview pane for the first time in 6 weeks.

Looks like they've fixed it. Finally.

What support library version should we use with targetSDK 28?

you can use Revision 28.0.0 Alpha 1 for android p
but it is a preview version

Visit https://developer.android.com/topic/libraries/support-library/packages for latest support-libraries



Related Topics



Leave a reply



Submit