Migrating to AndroidX

Viewed 13115

I upgraded my Android Studio to 3.2 and now I want to auto migrate to AndroidX using from Redactor->Migrate to AndroidX and now it has this error:

Android dependency 'androidx.media:media' has different version for the compile (1.0.0-rc01) and runtime (1.0.0) classpath. You should manually set the same version via DependencyResolution

4 Answers

Probably one of your dependencies uses androidx.media:media:1.0.0-rc1. You should use Gradle's Dependency Resolution Strategy to force all dependencies to use the same version.
Try to add the following code in your app level build.gradle and it should work.
Something like this:

android {
    compileSdkVersion 28

    defaultConfig {
       // Your code
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
       // Your build types if any
    }

    configurations.all {
        resolutionStrategy {
            force 'androidx.media:media:1.0.0'
        }
    }
}

You can also use this command to detect which of your dependencies uses androidx.media:media:

./gradlew :app:dependencies

Refactoring will change old imports to following:

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

You may want to use following instead if you do not plan to use legacy dependencies:

implementation 'androidx.appcompat:appcompat:1.0.0'

This will remove the issue as well if you are not using media at all...

Try to fix it manually.

Just change dependency to:

androidx.media:media:1.0.0

And change imports in your classes

I had the same issue, and i resolved it by using :

buildscript {
    ext{
        kotlin_version = '1.3.0' // Old 1.2.71
    ...
}

Endly i changed gradle version from 3.2.1 to 3.3.1:

dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:4.0.1'
...

I hope this will help.

Related