1

Okay, so I am using Retrofit, OkHttp and Picasso in my project. Here are my relevant dependencies in the project:

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')

The project builds but when it starts it crashes on Android versions <5.0 This is what I get in the log:

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) 

I've searched this error, and has found out that okhttp uses okio: Importing Picasso and OkHttp in Eclipse

But when I add the okio jar, I get this while building the app:

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

Somebody help please, this is really driving me nuts

Community
  • 1
  • 1
Anonomousxxx
  • 51
  • 1
  • 7

2 Answers2

3

You've with duplicate entry:

Error: java.util.zip.ZipException:duplicate entry

There is similiar question here : Error: java.util.zip.ZipException: duplicate entry

Problem is solved adding exclude on your dependencies. I cant tell you exactly which one of your dependencies needs to add exclude statement but you could try one by one.

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'
}
...

I hope it helps!!

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
  • Thanks for your answer, but still no success. Amazingly the duplicate error doesn't disappear until I remove the jar itself. I also tried to use gradle instead of jar to add okio, but than I get the first exception. Yet, amazingly, only on android versions <5.0 – Anonomousxxx Jan 28 '16 at 16:53
  • @Anonomousxxx add your okio.jar to your libs folder and try again changing exclude module: 'okio' instead of exclude module: 'com.squareup.okio' – Gueorgui Obregon Jan 28 '16 at 17:38
  • @Anonomousxxx Your problem was solved with module: 'okio' ? Please let me know to edit the answer ;) – Gueorgui Obregon Jan 28 '16 at 20:52
  • @g20 no, it still doesn't work, I get the duplicate error until I add exclude module to all libraries, and then I get the first error again – Anonomousxxx Jan 29 '16 at 09:43
  • @Anonomousxxx I think that is some bug related to okio or okhttp and you should report to their developers, they made a change because of this issue https://github.com/square/okhttp/issues/967 on Android L version, so I think that the change affect Android < 5.0 versions. Good luck ;) – Gueorgui Obregon Jan 29 '16 at 15:00
0

In the end turned out to be a multidex problem, solved by adding the support library for multidex https://developer.android.com/tools/support-library/features.html#multidex

Thanks guys for trying to help.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Anonomousxxx
  • 51
  • 1
  • 7