【问题标题】:Retrofit+OkHttp+Picasso okio dependency改造+OkHttp+毕加索okio依赖
【发布时间】:2016-01-28 16:12:18
【问题描述】:

好的,所以我在我的项目中使用了 Retrofit、OkHttp 和 Picasso。 以下是我在项目中的相关依赖项:

compile ('com.squareup.retrofit:retrofit:2.0.0-beta2')
compile ('com.squareup.retrofit:converter-gson:2.0.0-beta2')
compile ('com.squareup.okhttp:okhttp-urlconnection:2.5.0')
compile ('com.squareup.picasso:picasso:2.5.2')
compile 'com.squareup:otto:1.3.6'
compile ('com.squareup.okhttp:okhttp:2.5.0')

项目已构建,但在启动时在 Android 版本

01-28 18:03:54.103 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzb
01-28 18:03:54.543 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'retrofit.Retrofit$Builder', referenced from method by.set.pibox.helpers.ApiHelper.getInstance
01-28 18:03:54.568 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'okio.Buffer', referenced from method com.squareup.okhttp.internal.Util.toHumanReadableAscii
01-28 18:03:54.648 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'okio.Buffer', referenced from method by.set.pibox.helpers.ApiHelper$1.intercept
01-28 18:03:54.658 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'com.squareup.okhttp.internal.DiskLruCache$4', referenced from method com.squareup.okhttp.internal.DiskLruCache.<clinit>
01-28 18:03:54.678 20816-20816/by.set.pibox E/dalvikvm: Could not find class 'com.squareup.okhttp.internal.DiskLruCache$2', referenced from method com.squareup.okhttp.internal.DiskLruCache.newJournalWriter
01-28 18:03:58.888 20816-20816/by.set.pibox E/CrashlyticsCore: Failed to execute task.
                                                              java.util.concurrent.TimeoutException
                                                               at java.util.concurrent.FutureTask.get(FutureTask.java:173)
                                                               at com.crashlytics.android.core.CrashlyticsExecutorServiceWrapper.executeSyncLoggingException(CrashlyticsExecutorServiceWrapper.java:44)
                                                               at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:235)
                                                               at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                               at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
                                                               at dalvik.system.NativeStart.main(Native Method)
01-28 18:03:59.293 20816-20816/by.set.pibox E/AndroidRuntime: FATAL EXCEPTION: main
                                                          java.lang.ExceptionInInitializerError
                                                              at by.set.pibox.helpers.HelperFactory.setHelper(HelperFactory.java:112)
                                                              at by.set.pibox.PiboxApplication.onCreate(PiboxApplication.java:30)
                                                              at by.set.pibox.PiboxApplication_.onCreate(PiboxApplication_.java:32)
                                                              at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5056)
                                                              at android.app.ActivityThread.access$1300(ActivityThread.java:162)
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1432)
                                                              at android.os.Handler.dispatchMessage(Handler.java:99)
                                                              at android.os.Looper.loop(Looper.java:158)
                                                              at android.app.ActivityThread.main(ActivityThread.java:5751)
                                                              at java.lang.reflect.Method.invokeNative(Native Method)
                                                              at java.lang.reflect.Method.invoke(Method.java:511)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
                                                              at dalvik.system.NativeStart.main(Native Method)
                                                           Caused by: java.lang.ExceptionInInitializerError
                                                              at com.squareup.okhttp.Cache.<init>(Cache.java:172)
                                                              at com.squareup.okhttp.Cache.<init>(Cache.java:168)
                                                              at by.set.pibox.helpers.ApiHelper.<clinit>(ApiHelper.java:111)
                                                              at by.set.pibox.helpers.HelperFactory.setHelper(HelperFactory.java:112) 
                                                              at by.set.pibox.PiboxApplication.onCreate(PiboxApplication.java:30) 
                                                              at by.set.pibox.PiboxApplication_.onCreate(PiboxApplication_.java:32) 
                                                              at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) 
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5056) 
                                                              at android.app.ActivityThread.access$1300(ActivityThread.java:162) 
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1432) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                              at android.os.Looper.loop(Looper.java:158) 
                                                              at android.app.ActivityThread.main(ActivityThread.java:5751) 
                                                              at java.lang.reflect.Method.invokeNative(Native Method) 
                                                              at java.lang.reflect.Method.invoke(Method.java:511) 
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083) 
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850) 
                                                              at dalvik.system.NativeStart.main(Native Method) 
                                                           Caused by: java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.DiskLruCache$4
                                                              at com.squareup.okhttp.internal.DiskLruCache.<clinit>(DiskLruCache.java:809)
                                                              at com.squareup.okhttp.Cache.<init>(Cache.java:172) 
                                                              at com.squareup.okhttp.Cache.<init>(Cache.java:168) 
                                                              at by.set.pibox.helpers.ApiHelper.<clinit>(ApiHelper.java:111) 
                                                              at by.set.pibox.helpers.HelperFactory.setHelper(HelperFactory.java:112) 
                                                              at by.set.pibox.PiboxApplication.onCreate(PiboxApplication.java:30) 
                                                              at by.set.pibox.PiboxApplication_.onCreate(PiboxApplication_.java:32) 
                                                              at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) 
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5056) 
                                                              at android.app.ActivityThread.access$1300(ActivityThread.java:162) 
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1432) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                              at android.os.Looper.loop(Looper.java:158) 
                                                              at android.app.ActivityThread.main(ActivityThread.java:5751) 
                                                              at java.lang.reflect.Method.invokeNative(Native Method) 
                                                              at java.lang.reflect.Method.invoke(Method.java:511) 
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083) 
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850) 
                                                              at dalvik.system.NativeStart.main(Native Method) 

我搜索了这个错误,发现okhttp使用了okio: Importing Picasso and OkHttp in Eclipse

但是当我添加 okio jar 时,我在构建应用程序时得到了这个:

Error:Execution failed for task            ':pibox:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException:    java.util.zip.ZipException: duplicate entry: okio/AsyncTimeout$1.class

请大家帮忙,这真的让我发疯了

【问题讨论】:

  • 我只是在猜测:使用较新版本的 okhttp,okhttp-urlconnection 不是已经包含在 okhttp 中了吗?
  • @Andrei,试过了,没用(
  • 那些“找不到类”错误是否有可能来自使用 ProGuard?不过可能不相关。

标签: android android-studio retrofit okhttp square


【解决方案1】:

你有重复的条目:

错误:java.util.zip.ZipException:重复条目

这里有类似的问题:Error: java.util.zip.ZipException: duplicate entry

在您的依赖项上添加exclude 即可解决问题。我不能确切地告诉您您的哪个依赖项需要添加exclude 语句,但您可以一一尝试。

compile ('com.squareup.retrofit:retrofit:2.0.0-beta2') {
    exclude module: 'com.squareup.okio'
}
compile ('com.squareup.retrofit:converter-gson:2.0.0-beta2') {
    exclude module: 'com.squareup.okio'
}
compile ('com.squareup.okhttp:okhttp-urlconnection:2.5.0') {
    exclude module: 'com.squareup.okio'
}
...

希望对你有帮助!

【讨论】:

  • 感谢您的回答,但仍然没有成功。令人惊讶的是,直到我移除 jar 本身,重复错误才会消失。我也尝试使用 gradle 而不是 jar 来添加 okio,但是我得到了第一个异常。然而,令人惊讶的是,仅在 的 android 版本上
  • @Anonomousxxx 将您的 okio.jar 添加到您的 libs 文件夹并再次尝试更改排除模块:'okio' 而不是排除模块:'com.squareup.okio'
  • @Anonomousxxx 您的问题已通过 module: 'okio' 解决?请让我知道编辑答案;)
  • @g20 不,它仍然不起作用,我得到重复的错误,直到我将排除模块添加到所有库,然后我再次得到第一个错误
  • @Anonomousxxx 我认为这是与 okio 或 okhttp 相关的一些错误,您应该向他们的开发人员报告,他们因为这个问题在 Android L 版本上进行了更改github.com/square/okhttp/issues/967,所以我认为更改影响 Android
【解决方案2】:

最后竟然是multidex问题,通过添加multidex的支持库解决 https://developer.android.com/tools/support-library/features.html#multidex

感谢大家帮忙。

【讨论】:

    猜你喜欢
    • 2015-11-15
    • 2015-11-25
    • 2017-10-15
    • 2014-03-02
    • 2016-01-25
    • 2014-07-12
    • 2018-04-13
    • 1970-01-01
    • 2021-03-17
    相关资源
    最近更新 更多