2017-04-13 5 views
1

rxJavaを使用して取得リクエストを送信し、改造します。私がやった方法は、私がPOSTモデルとApiCallという名前のインターフェイスを作成し、私もGradleの中に、次の依存を追加することです:rxJavaをインポートする際のMETA-INFエラー

私はこのようにやった ApiCallインタフェースで
compile 'com.squareup.retrofit2:retrofit:2.2.0' 

compile 'com.android.support:recyclerview-v7:25.3.1' 
compile 'com.android.support:design:25.3.1' 

compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
compile 'io.reactivex.rxjava2:rxjava:2.0.1' 

compile 'com.android.support.constraint:constraint-layout:1.0.2' 

compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 
compile 'com.squareup.retrofit2:converter-gson:2.0.0' 

compile 'com.google.code.gson:gson:2.4' 

public interface ApiCall { 
    String SERVICE_ENDPOINT = "https://myserverIp"; 
    @GET("/api/post") 
    io.reactivex.Observable<Post> getPost(); 
} 

そして、私の活動のonResume()でIこの本のように:

@Override 
    protected void onResume() { 
     super.onResume(); 
     Retrofit retrofit=new Retrofit.Builder() 
       .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .baseUrl("https://198.50.214.15/") 
       .build(); 
     ApiCall apiService=retrofit.create(ApiCall.class); 

     Observable<Post> observable=apiService.getPost(); 

     observable.subscribeOn(Schedulers.newThread()) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .subscribe(responseData -> { 
        messageList.add(responseData.getTitle()); 
        postAdapter.notifyDataSetChanged(); 
       }); 

    } 

最終的に私はこのエラーを取得:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. 
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties 
    File1: /home/hussein/.gradle/caches/modules-2/files-2.1/io.reactivex.rxjava2/rxjava/2.0.1/57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb/rxjava-2.0.1.jar 
    File2: /home/hussein/.gradle/caches/modules-2/files-2.1/io.reactivex/rxjava/1.1.1/b494968f6050d494de55dc3ce005e59c7eb40012/rxjava-1.1.1.jar 
+0

をされるためRxJava ** 1 ** - HTTP ://stackoverflow.com/a/42050569/7045114 –

答えて

2

あなたはからそのファイル除外することがあります:あなたは改修のためRXJava ** 2 **プロジェクトではなく、呼び出しアダプタを使用している

android { 
    ... 
    packagingOptions { 
     exclude 'META-INF/rxjava.properties' 
    } 
} 
関連する問題