必须将Observable返回类型参数化为Observable <foo>或Observable <! - ?扩展Foo - >

时间:2015-11-17 10:51:58

标签: android retrofit rx-java rx-android

我正在使用改装2.0.0-beta2并且调试版本正常运行但我在使用Proguard进行版本构建时遇到以下错误。

这是更新的logcat错误。

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

接口:

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

片段:

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;
}

1 个答案:

答案 0 :(得分:3)

现在它通过将这些属性放在Proguard中来工作。

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

这里是完整设置

##---------------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  ----------