将targetSdkVersion更新为27后,我收到此错误消息 .
所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃) . 发现版本27.0.2,25.2.0 . 示例包括com.android.support:animated-vector-drawable:27.0.2和com.android.support:support-media-compat:25.2.0
我知道我应该更新 com.android.support:support-media-compat
但我不知道如何因为我没有在build.gradle中使用它,我试图更新SDK工具但问题仍然存在 . bellow是build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.ex"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.android.gms:play-services-ads:11.6.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bloder:magic:1.1'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
}
6 回答
我更新了gradle时遇到了类似的问题 . 我隐含地声明了写入支持库的错误 . 我必须为另外3个支持库隐式执行此操作 . 通过隐式声明支持库无法解决此错误 . 如果您想立即解决问题,请将所有27.0.2替换为com.android.support . *库中的25.2.0 .
你正在处理的似乎是传递依赖 . 换句话说,正如你使用gradle所以你不要't have to re-invent the wheel the maker of the dependency you are using also uses dependencies. It appears the problem is with this dependency ' com.github.bloder:magic:1.1 ' because it depends on ' com.android.support:appcompat-v7:23.1.1' . 我通过访问the repository pom description找到了博客魔术 . 在android studio中我也可以点击右侧的gradle选项卡,找到一个依赖任务并以这种方式发现冲突 . 现在我们知道问题excluding a transitive dependency可能有助于检查所有依赖关系是否是最新的可能有助于或不使用博客魔法可能会有所帮助 . 我知道,这个问题很难 . 希望这会有所帮助 .
我已经手动检查了项目中的库 - > .myidea->库,然后我发现我有两个使用旧版本的库:
然后只需在builde.gradle中添加此行
错误现在消失了 .
我遇到了完全相同的问题 . 您没有在build.graddle中使用,但是build.graddle中包含的某些库正在使用 . 因此,您需要在build.graddle中覆盖它们(在警告中指向)
我以前遇到过这个错误 . 尝试在Android Studio工具栏上点击构建 .
清洁构建
在步骤2之后,单击“重建项目” .
Update 如果没有,请尝试将
implementation com.android.support:support-media-compat:27.0.2
明确添加到构建中正如您已经看到上面的所有答案和评论,但这个答案是为了清除新开发人员可能无法轻易获得的内容 .
./gradlew -q dependencies app:dependencies --configuration compile
上面这行将毫无疑问地挽救你的生命,但是如何从上面的结果中得到确切的观点 .
当您从上面的命令获得所有依赖关系图表或列表时,您必须搜索您在代码中获得的冲突版本号 . 请看下面的图片 .
在上面的图像中,您可以看到 23.4.0 正在创建问题,但我们无法在gradle文件中找到它 . 所以现在这个版本号(23.4.0)将节省我们 . 当我们有这个数字时,我们会在上面的命令结果的结果中找到这个数字,并直接在我们的gradle文件中直接导入该依赖项 . 请参阅下图以获得清晰的视图 .
你可以清楚地看到 com.android.support:cardview-v7:23.4.0 和 com.android.support:customtabs:23.4.0 正在使用创建问题的版本 . 现在只需从依赖列表中复制这些行,并在我们的gradle文件中显式使用,但使用更新的版本链接
implementation "com.android.support:cardview-v7:26.1.0" implementation "com.android.support:customtabs:26.1.0"
请参考这个以查看原始答案https://stackoverflow.com/a/49169228/4156595