我有以下依赖脚本:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.asdf.asdf"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'YOUTUBE_API_KEY', YoutubeApiKey
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0-beta-2'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:0.13.2'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
javanano {
option 'ignore_services=true'
}
}
task.plugins {
grpc {
option 'nano=true'
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
compile 'com.android.support:customtabs:23.2.1'
compile 'com.google.apis:google-api-services-youtube:v3-rev164-1.21.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.grpc:grpc-protobuf-nano:0.13.2'
compile 'io.grpc:grpc-okhttp:0.13.2'
compile 'io.grpc:grpc-stub:0.13.2'
compile 'com.google.guava:guava:18.0'
}
虽然 youtube 库和 grpc 库都依赖于 google guava 库,但它们依赖于不同的版本,从而导致冲突。 YouTube 依赖于 com.google.guava:guava-jdk5:17.0
,而 grpc 依赖于 com.google.guava:guava:18.0
。(请注意 Artifact 差异,如果可能相关)问题是 grpc 最终尝试找到 youtube 版本的 guava 中定义的方法,而该方法仅存在于其自己版本的依赖项中。我该如何解决这个问题?
错误消息
FATAL EXCEPTION: SyncAdapterThread-1
Process: com.asdf.asdf, PID: 4025
java.lang.NoSuchMethodError: No static method directExecutor()Ljava/util/concurrent/Executor; in class Lcom/google/common/util/concurrent/MoreExecutors; or its super classes (declaration of 'com.google.common.util.concurrent.MoreExecutors' appears in /data/data/com.fentale.dalol/files/instant-run/dex/slice-guava-jdk5-17.0_a8ada10dcaf113cb6e3b4d3e5b46975833f8ae8f-classes.dex)
at io.grpc.internal.ClientCallImpl.<init>(ClientCallImpl.java:100)
at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:320)
at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:299)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:130)
at com.fentale.dalol.nano.DalolGrpc$DalolBlockingStub.topPosts(DalolGrpc.java:365)
方法“directExecutor”在 guava-v18 中定义,但 grpc 尝试从 guava-jdk5 访问它。
最佳答案
我会尝试使用排除 guava-jdk5
exclude module: 'guava-jdk5'
在您的依赖项中。
问题是,如果 Artifact 具有不同的名称(如此处的 guava 和 guava-jdk5),则无法检测版本冲突。然后可能会发生加载错误的类,因为两个 jar 都包含在内。
关于android - gradle依赖版本冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401937/