1

I'm going to send get request using rxJava and retrofit. The way that I did is that I created POST model and a interface named ApiCall and I also add the following dependent in the gradle:

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'

In the ApiCall interface I did like this:

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

And in my activity's onResume() I this like this:

 @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();
                });

    }

finally i get this error:

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
azizbekian
  • 60,783
  • 13
  • 169
  • 249
Hussein Ojaghi
  • 2,260
  • 3
  • 23
  • 41
  • You are using RXJava**2** in your project, but call adapter for Retrofit is for RxJava**1** - http://stackoverflow.com/a/42050569/7045114 – Maksim Ostrovidov Apr 14 '17 at 00:59

1 Answers1

2

You have to exclude that file from packagingOptions:

android {
    ...
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
}
azizbekian
  • 60,783
  • 13
  • 169
  • 249