androidretrofitrx-javarx-android

Observable return type must be parameterized as Observable<Foo> or Observable<? extends Foo>


I'm using retrofit 2.0.0-beta2 and debug build is working properly but I'm getting the following error on release build with Proguard.

Here's the updated logcat errors.

11-17 18:23:22.751 16274-16274/ph.reggis.FEDT D/AndroidRuntime: Shutting down VM
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime: FATAL EXCEPTION: main
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime: Process: ph.reggis.FEDT, PID: 16274
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {ph.reggis.FEDT/ph.reggis.FEDT.view.activity.NotificationListActivity}: java.lang.IllegalArgumentException: Unable to create call adapter for class b.a
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     for method InsularFMService.getNews
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:  Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for class b.a
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     for method InsularFMService.getNews
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.Utils.methodError(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.MethodHandler.createCallAdapter(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.MethodHandler.create(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.Retrofit.loadMethodHandler(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.Retrofit$1.invoke(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at java.lang.reflect.Proxy.invoke(Proxy.java:393)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at $Proxy0.getNews(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at ph.reggis.FEDT.b.C.d(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at ph.reggis.FEDT.view.fragment.NotificationListFragment.t(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at ph.reggis.FEDT.view.fragment.NotificationListFragment.l(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.B.a(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.B.a(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.B.a(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.B.i(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.y.i(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v4.b.t.onPostResume(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.support.v7.a.B.onPostResume(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.Activity.performResume(Activity.java:6336)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:  Caused by: java.lang.IllegalStateException: Observable return type must be parameterized as Observable<Foo> or Observable<? extends Foo>
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.RxJavaCallAdapterFactory.get(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.Retrofit.nextCallAdapter(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:     at retrofit.Retrofit.callAdapter(Unknown Source)
11-17 18:23:22.752 16274-16274/ph.reggis.FEDT E/AndroidRuntime:         ... 28 more

Interface:

@GET("news")
Observable<News> getNews();

Fragment:

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(Constant.WS_URL_BASE)
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
        .build();

InsularFMService fmService = retrofit.create(InsularFMService.class);

//Observable<News> observable = fmService.getNews();
//subscription = observable. - ALSO NOT WORKING

subscription = fmService.getNews().
        .observeOn(AndroidSchedulers.mainThread())
        .subscribeOn(appController.getDefaultScheduler())
        .subscribe(new Subscriber<News>() {...

Graddle:

compile "com.squareup.retrofit:retrofit:2.0.0-beta2"
compile "com.squareup.retrofit:converter-gson:2.0.0-beta2"
compile "com.squareup.retrofit:adapter-rxjava:2.0.0-beta2"

Proguard:

# Fixed: Caused by: java.lang.NoSuchFieldException: No field producerIndex
 -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
     long producerIndex;
     long consumerIndex;
 }
 -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
     long producerNode;
     long consumerNode;
}

Solution

  • Now it's working by putting these attributes inside the Proguard.

    # Application classes that will be serialized/deserialized over Gson
    -keep class ph.reggis.FEDT.model.api.** { *; }
    

    Here's the full settings

    ##---------------Begin: proguard configuration for Gson  ----------
    # Gson uses generic type information stored in a class file when working with fields. Proguard
    # removes such information by default, so configure it to keep all of it.
    -keepattributes Signature
    -keepattributes *Annotation*
    
    # Gson specific classes
    -keep class sun.misc.Unsafe { *; }
    
    # Application classes that will be serialized/deserialized over Gson
    -keep class ph.reggis.FEDT.model.api.** { *; }
    
    ##---------------End: proguard configuration for Gson  ----------