2017-06-16 6 views
0

AndroidでGrpcクライアントを作成したいと思います。私はここでthis tutorialAndroid用のProtobuf:エラーコンパイル時にProtocファイルに定義された重複クラス

に従ってください、私の外側build.gradleファイルです:私はプロジェクトをビルドしようとしたとき、私は常にエラーを満たす

dependencies { 
    compile 'com.android.support:appcompat-v7:23.+' 

    // You need to build grpc-java to obtain these libraries below. 
    compile 'io.grpc:grpc-okhttp:1.3.0' // CURRENT_GRPC_VERSION 
    compile 'io.grpc:grpc-protobuf-lite:1.3.0' // CURRENT_GRPC_VERSION 
    compile 'io.grpc:grpc-stub:1.3.0' // CURRENT_GRPC_VERSION 
    compile 'javax.annotation:javax.annotation-api:1.2' 
} 

:ここ

apply plugin: 'java' 
apply plugin: 'com.google.protobuf' 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.1' 
     classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0" 

    } 
} 

protobuf { 
    protoc { 
     artifact = "com.google.protobuf:protoc:3.2.0" 
    } 
    plugins { 
     grpc { 
      artifact = 'io.grpc:protoc-gen-grpc-java:1.3.0' 
     } 
    } 
    generateProtoTasks { 
     all()*.plugins { 
      grpc {} 
     } 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
     mavenLocal() 
    } 
} 

は私の内側のファイルがbuild.gradleファイルです

Error:(14, 15) error: duplicate class: io.grpc.routeguideexample.Feature 
Error:(13, 15) error: duplicate class: io.grpc.routeguideexample.FeatureDatabase 
// ... 

Feature ...私はprotocファイルで定義したクラスです。私のコードで何が間違っているのか理解してください。あなたのコード内のJavaクラスio.grpc.routeguideexample.Featureを定義した場合

おかげ

答えて

0

が、これはあなたが説明したエラーの原因となって、route_guide.protoファイルから生成されたクラス名と競合します。自分のFeatureFeatureDatabaseクラスの名前またはパッケージを変更するか、別のJavaパッケージ名を使用するようにroute_guide.protoを変更することができます。一般に、build/generated/source/proto/.../javalite/io/grpc/routeguideexample/のようなディレクトリを探して、protoファイルから実際に生成されたコードを見ることができます。

関連する問題