uber / RIBs

Uber's cross-platform mobile architecture framework - Android Repository
https://eng.uber.com/tag/ribs/
Apache License 2.0
7.77k stars 907 forks source link

[Android] RIB and Retrofit2 #224

Closed datnt1987 closed 6 years ago

datnt1987 commented 6 years ago

Hi, I use retrofit2 to call API, my WeatherBuilder looks like:

@dagger.Module
    public abstract static class Module {

        @WeatherScope
        @Binds
        abstract WeatherInteractor.WeatherPresenter presenter(WeatherView view);

        @WeatherScope
        @Provides
        static WeatherRouter router(
                Component component,
                WeatherView view,
                WeatherInteractor interactor) {
            return new WeatherRouter(view, interactor, component);
        }

        // TODO: Create provider methods for dependencies created by this Rib. These should be static.
        @WeatherScope
        @Provides
        @Named("retrofitApi")
        static Retrofit provideRetrofit() {
            return new Retrofit.Builder()
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .baseUrl("http://samples.openweathermap.org/data/2.5/")
                    .build();
        }

        @WeatherScope
        @Provides
        static APIStore.RequestService provideAPIService(@Named("retrofitApi") Retrofit retrofit) {
            return retrofit.create(APIStore.RequestService.class);
        }

        @WeatherScope
        @Provides
        static APIStore.Repository provideAPIRepository(APIStore.RequestService requestService) {
            return new APIRepository(requestService);
        }

    }

So when running project, It crashed and threw exception:

Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable

So please tell me how to solve it.

Note: my gradle file

implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    // Retrofit
    api 'com.squareup.retrofit2:retrofit:2.3.0'
    api 'com.google.code.gson:gson:2.8.1'
    api 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    api 'com.squareup.retrofit2:converter-gson:2.3.0'
    // RIBs
    annotationProcessor 'com.uber.rib:rib-compiler-test:0.9.1'
    compile 'com.uber.rib:rib-android:0.9.1'
    testCompile 'com.uber.rib:rib-test-utils:0.9.1'

    api 'com.jakewharton.rxbinding2:rxbinding:2.1.1'

when adding adater-rxjava, I met error about META-INF/rxjava.properties, then I added this

packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
datnt1987 commented 6 years ago

Problem is solved