Anthony Anthony - 3 years ago 252
Android Question

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download