Android Studio 3.1: mixing versions can lead to ru

2020-06-01 07:31发布

问题:

Have recently upgraded to Android Studio 3.1, and at the same time I'm trying the Android P preview.

I'm getting the following error on compiling:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0-alpha1, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0-alpha1 and com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

But I cannot see any instance of 26.1.0 anywhere. All I have in my gradle is:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'

I've tried clearing caches, rebuilding app, etc. But error remains.

回答1:

You need to override the conflicted libraries by adding the conflicted libraries to your dependencies block

dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:customtabs:28.0.0-alpha1'
implementation 'com.android.support:support-vector-drawable:28.0.0-alpha1'
implementation 'com.android.support:support-media-compat:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'


回答2:

The above warning is not specific to media-compat dependency. They just added example to explain the issue. The issue get resolved by adding v4 lib for me.

implementation 'com.android.support:support-v4:28.0.0'

in addition to

implementation 'com.android.support:appcompat-v7:28.0.0'

No need include

implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'


回答3:

You need to override the conflicted libraries by adding the conflicted libraries to your dependencies block. For example, from your error log you'll find the following:

Found versions 28.0.0-alpha1, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0-alpha1 and com.android.support:support-media-compat:26.1.0 less...

You can remove the error by adding the libraries with something like this:

dependencies {
   implementation 'com.android.support:animated-vector-drawable:28.0.0-alpha1`
   implementation 'com.android.support:support-media-compat:28.0.0-alpha1`
}


回答4:

this error came,when i connect app to firebase.

no need to add any thing.

just put mouse cursor on error line(below one) and press Alt+Enter

(implementation 'com.android.support:appcompat-v7:28.0.0')

in the list enter first option.(noinspection)

After that it looks like this,

//noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0'



回答5:

Some dependency — perhaps playLicensing — has a transitive dependency on at least support-media-compat, for version 26.1.0.

To work around this:

  • Identify each Support Library artifact that shows up in "External Libraries" that is older than 28.0.0-alpha1. Based on the error, those older ones should all be 26.1.0, and it will be at least support-media-compat.

  • For each of those, add your own implementation line to your dependencies, requesting that artifact, but for 28.0.0-alpha1. This will cause Gradle to use the newer artifact, which happens to be what you want.

  • Hope that whatever is depending on those older artifacts will survive with the newer artifacts.

So, at minimum, you are adding:

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


回答6:

In my case I resolved it by adding this below the error line.

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


回答7:

add in dependencies of build.grad (Module.app)

dependencies {
 //noinspection GradleCompatible
 implementation 'com.android.support:appcompat-v7:28.0.0'
 implementation 'com.android.support:animated-vector-drawable:28.0.0'
 implementation 'com.android.support:support-media-compat:28.0.0'
}


回答8:

In my case adding support-v4 helped me to got loose of warning.

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'

    // other dependencies
}


回答9:

Are you using a firebase in your project? Using firebase core or firebase app indexing seem to be causing the problem. I was having the same problem, but commenting on firebase packages makes the error to go away

//    implementation 'com.google.firebase:firebase-core:16.0.8'
//    implementation 'com.google.firebase:firebase-ads:17.2.0'
//    implementation 'com.google.firebase:firebase-appindexing:17.1.0'


回答10:

Simple and easy solution is to add manually conflicting versions of android-support.

Mixing version can lead to runtime crashes

Just follow and solve your issue.

go to your gradle script-->build gradle(Module:app) in the dependency section and implement the conflicting version for ease go to the link.

Make sure there is no space during implementation.

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

you can follow the link.



回答11:

I think your gradle file has the below dependency. Add this to your app level build.gradle.

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:mediarouter-v7:28.0.0-alpha1'
implementation 'com.android.support:support-vector-drawable:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'