Robospice + Retrofit 2:分配转换器

时间:2016-03-11 08:57:51

标签: android robospice retrofit2

我在互联网上寻找了Robospice + Retrofit 2的例子,但我找不到任何东西。我自己正在建立一个例子但是有以下例外:

9:40:56.516 3553-3553/? E/AndroidRuntime: FATAL EXCEPTION: main
     Process: com.carlos.robospiceexample, PID: 3553
     java.lang.NoClassDefFoundError: Failed resolution of: Lretrofit/converter/GsonConverter;
         at com.octo.android.robospice.retrofit.RetrofitGsonSpiceService.createConverter(RetrofitGsonSpiceService.java:37)
         at com.octo.android.robospice.retrofit.RetrofitSpiceService.getConverter(RetrofitSpiceService.java:42)
         at com.octo.android.robospice.retrofit.RetrofitGsonSpiceService.createCacheManager(RetrofitGsonSpiceService.java:31)
         at com.octo.android.robospice.SpiceService.onCreate(SpiceService.java:108)
         at com.octo.android.robospice.retrofit.RetrofitSpiceService.onCreate(RetrofitSpiceService.java:27)
         at com.carlos.robospiceexample.SampleRetrofitSpiceService.onCreate(SampleRetrofitSpiceService.java:14)
         at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)
         at android.app.ActivityThread.access$1800(ActivityThread.java:151)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386)
         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.ClassNotFoundException: Didn't find class "retrofit.converter.GsonConverter" on path:
             DexPathList[[zip file "/data/app/com.carlos.robospiceexample-1/base.apk"],
             nativeLibraryDirectories=[/vendor/lib, /system/lib]]
         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
         at com.octo.android.robospice.retrofit.RetrofitGsonSpiceService.createConverter(RetrofitGsonSpiceService.java:37) 
         at com.octo.android.robospice.retrofit.RetrofitSpiceService.getConverter(RetrofitSpiceService.java:42) 
         at com.octo.android.robospice.retrofit.RetrofitGsonSpiceService.createCacheManager(RetrofitGsonSpiceService.java:31) 
         at com.octo.android.robospice.SpiceService.onCreate(SpiceService.java:108) 
         at com.octo.android.robospice.retrofit.RetrofitSpiceService.onCreate(RetrofitSpiceService.java:27) 
         at com.carlos.robospiceexample.SampleRetrofitSpiceService.onCreate(SampleRetrofitSpiceService.java:14) 
         at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761) 
         at android.app.ActivityThread.access$1800(ActivityThread.java:151) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386) 
         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) 
        Suppressed: java.lang.ClassNotFoundException: retrofit.converter.GsonConverter
         at java.lang.Class.classForName(Native Method)
         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                ... 17 more
      Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
03-11 09:40:56.519 3553-3553/? I/Process: Sending signal. PID: 3553 SIG: 9

我认为错误是因为我没有分配Converter。但是当试图声明Converter时,方法的返回类型来自Retrofit 1:

enter image description here

这让我觉得不可能将Retrofit 2与Robospice一起使用。

我是对的吗?可以做些什么吗?

提前致谢。

1 个答案:

答案 0 :(得分:1)

这还不可能。但人们是asking for it。来自开发者:

  

...个人我没时间像以前一样维护lib   参与其他OSS项目。欢迎贡献者。

     

斯特凡