将Android Studio从 Canary 3 更新为 Canary 4 后,在构建时抛出以下错误 .
Android依赖项'com.android.support:support-support-v4'具有不同版本的编译(25.2.0)和运行时(26.0.0-beta2)类路径 . 您应该通过DependencyResolution手动设置相同的版本 .
我在整个项目中运行了一个完整的搜索,版本 25.1.0
没有使用 .
App-build.gradle
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
applicationId "com.xxx.xxxx"
minSdkVersion 14
targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
debug {
debuggable true
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
lintOptions {
abortOnError false
}
}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation project(':core')
implementation com.google.android.gms:play-services-gcm:9.0.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true
}
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.flurry.android:analytics:7.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
implementation 'com.jakewharton:butterknife:8.6.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
Library-build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion
versionCode 1
versionName "1.0"
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/model.jar')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:percent:26.0.0-beta2'
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
implementation 'com.android.support:support-core-utils:26.0.0-beta2'
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.picasso:picasso:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}
Note: 项目在Canary 3建造得很好
11 回答
在您的buildscript(build.gradle root)中使用此代码:
我有同样的错误,解决了我的问题是什么 . 在我的 library 而不是使用编译或实现我使用"api" . 所以最后我的依赖:
你可以在这个链接中找到有关"api","implementation"的更多信息https://stackoverflow.com/a/44493379/3479489
通过为项目运行正确的
gradle -q dependencies
命令,您应该能够确切地看到奇怪版本中的哪个依赖项作为传递依赖项:https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies
一旦你追踪到它的内容,你可以在gradle文件中添加一个排除到特定的依赖项,例如:
经过很多时间并得到一位朋友的帮助,这位朋友比我更了解android:app / build.gradle
和依赖
在build.gradle中
在gradle.properties中
我的解决方案:在依赖项部分的app / src / build.gradle中添加以下行:
或者:在我的情况下为27.1.1
我按照Eddi上面提到的那样解决了这个问题,
我的答案是将此添加到我的
build.gradle
文件中:就我而言,将决议策略包含在
configurations.all { .. }
块中是必要的 . 我将configurations.all
块直接放入我的app/build.gradle
文件中(即configurations.all
未嵌套在其他任何内容中)将我的冲突依赖项从实现切换到api就可以了 . 这是Mindorks解释差异的好文章 .
https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa
编辑:
这也是我的依赖性解决方案
我评论出
//api 'com.google.android.gms:play-services-ads:15.0.1'
它在同步后对我有用在您的库项目中看到 compileSdkVersion 和 targetSdkVersion 版本与您的应用程序相同
也使所有依赖关系达到同一级别
将硬编码版本替换为示例: