我将Android Studio升级到3.2,现在想通过编辑器
->迁移至AndroidX
自动迁移,但出现以下错误:
Android依赖项'androidx.media:media'在编译时(1.0.0-rc01)和运行时(1.0.0)classpath中具有不同的版本。应手动通过DependencyResolution设置相同的版本。
可能是您的某个依赖项使用了androidx.media:media:1.0.0-rc1
。 您应该使用Gradle的依赖项解析策略来强制所有依赖项使用相同的版本。
尝试在您的应用程序级别的build.gradle
中添加以下代码,它应该可以正常工作。
类似于这样:
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'
}
}
}
您还可以使用此命令来检测哪些依赖项使用了 androidx.media:media
:
./gradlew :app:dependencies
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
如果您根本没有使用媒体,那么这也将解决问题...
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
对我有用。 - Hrishikesh Kadam尝试手动修复。
只需将依赖项更改为:
androidx.media:media:1.0.0
并在您的类中更改导入。
我曾经遇到过同样的问题,后来通过使用以下方法解决了:
buildscript {
ext{
kotlin_version = '1.3.0' // Old 1.2.71
...
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.0.1'
...
希望这能有所帮助。
dependencies
声明之前添加。 - 2hamed