与rxjava Single一起使用改造2时的Proguard错误

时间:2018-10-12 11:51:48

标签: android kotlin retrofit rx-java proguard

我在Kotlin上具有翻新的api接口:

interface CommonApi {
    @GET("config")
    fun getConfig(): Single<ConfigModel>
}

我将其与RxJava一起使用。我的改装提供商:

Retrofit.Builder()
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(okHttpClient)
                .baseUrl(HTTP_URL)
                .build()

当我在没有proguard的情况下使用它时,它工作正常。但是在使用proguard的情况下,我得到了例外(对堆栈跟踪进行模糊处理):

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.activities.SplashActivity}: java.lang.IllegalArgumentException: Unable to create call adapter for g.i<com.myapp.main.model.ConfigModel>
        for method CommonApi.getConfig
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for g.i<com.myapp.main.model.ConfigModel>
        for method CommonApi.getConfig
        at retrofit2.ServiceMethod$Builder.build(Unknown Source)
                                           parseMethodAnnotation
                                           parseHttpMethodAndPath
                                           parseHeaders
                                           parseParameter
                                           parseParameterAnnotation
                                           validatePathName
                                           methodError
                                           methodError
                                           parameterError
                                           parameterError
        at retrofit2.ServiceMethod$Builder.createCallAdapter(Unknown Source)
        at retrofit2.ServiceMethod$Builder.build(Unknown Source)
                                           parseMethodAnnotation
                                           parseHttpMethodAndPath
                                           parseHeaders
                                           parseParameter
                                           parseParameterAnnotation
                                           validatePathName
                                           methodError
                                           methodError
                                           parameterError
                                           parameterError
        at retrofit2.Retrofit.create(Unknown Source)
                              loadServiceMethod
                              callFactory
                              callAdapter
                              nextCallAdapter
                              requestBodyConverter
                              nextRequestBodyConverter
                              nextResponseBodyConverter
        at retrofit2.Retrofit$1.invoke(Unknown Source)
        at java.lang.reflect.Proxy.invoke(Proxy.java:397)
        at $Proxy4.getConfig(Unknown Source)
        at com.myapp.main.interactor.FirstLoadingInteractor.refreshConfig(Unknown Source)
        at com.myapp.mvp.presenters.SplashPresenter.firstLoading(Unknown Source)
                                                                               onSaveInstanceState
        at com.myapp.activities.SplashActivity.onCreate(Unknown Source)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            ... 10 more
 Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for g.i<com.myapp.main.model.ConfigModel>.
      Tried:
       * f.a.a.e
       * f.f
        at retrofit2.Retrofit.create(Unknown Source)
                              loadServiceMethod
                              callFactory
                              callAdapter
                              nextCallAdapter
                              requestBodyConverter
                              nextRequestBodyConverter
                              nextResponseBodyConverter
        at retrofit2.Retrofit.create(Unknown Source)
                              loadServiceMethod
                              callFactory
                              callAdapter
                              nextCallAdapter
                              requestBodyConverter
                              nextRequestBodyConverter
                              nextResponseBodyConverter

如果我将返回类型从Single更改为Observable使用proguard 可以正常工作:

interface CommonApi {
    @GET("config")
    fun getConfig(): Observable<ConfigModel>
}

此问题的原因是什么?我该如何解决此问题并在改造中使用Singles?

0 个答案:

没有答案