2016-04-04 15 views
1

は、私は次の依存関係スクリプトを持っている:ユーチューブライブラリとgrpcライブラリの両方がGoogleグアバライブラリに依存しているGradleの依存関係のバージョンの競合

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はcom.google.guava:guava-jdk5:17.0に依存しており、grpcはcom.google.guava:guava:18.0です(アーティファクトの違いがある可能性があることに注意してください)。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" はグアバ-V18に定義され、しかしgrpcはguava-jdk5からアクセスしようとしています。

+0

を追加し、より詳細enter image description here は、添付のスクリーンショットを確認してください。 – barq

+0

あなたのグラデルの最後の行を削除してください – barq

+0

@barqあなたの指示に従って最後の行(グアバの依存関係)を追加しました。動作しません。また、プロジェクトビルドでも同じ結果を得ようとしました。 –

答えて

2

を使用することができるトップレベルのGradleインチ

アーティファクトの名前が異なる場合(ここでは、guavaとguava-jdk5など)、バージョンの競合が検出されないという問題があります。次に、両方のjarが含まれているため、間違ったクラスがロードされることがあります。

+0

ありがとうございます。 コンパイル( 'com.google.apis:google-api-services-youtube:v3-rev164-1.21.0'){ 除外モジュール: 'guava-jdk5' } それはそれでした。 –

1

手動

compile 'com.google.guava:guava:18.0.0' 

だからあなたの依存関係は、あなたが使用することグアバV18を強制する方法は、以下の

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    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 'com.google.guava:guava:18.0.0' 
} 

なりグアバのバージョンを指定します。

それとも、私はあなたの依存関係で

exclude module: 'guava-jdk5' 

を使用してグアバ-JDK5を除外しようとする

configurations.all { 
    resolutionStrategy.force 'com.google.guava:guava:18.0.0' 
} 
0

あなたは

依存関係の内部
exclude module: 'guava-jdk5' 

にプロジェクトレベルbuild.gradleあなたが持っているを編集する必要があります。あなたがfirebaseプラグインを使用している場合は、あなたのエラーメッセージを貼り付けてください

classpath ('com.google.firebase:firebase-plugins:1.1.0') { 
     exclude group: 'com.google.guava', module: 'guava-jdk5' 
    } 
関連する問題