java.lang.NoClassDefFoundError: com.squareup.okhttp.MediaType

java.lang.NoClassDefFoundError: com.squareup.okhttp.MediaType

我在将代码从默认 HTTPClient 更改为 OkHTTP 时遇到此错误。通过网络搜索,但它没有得到解决。

我对来自 here and also with dependencyOkHTTP 库进行了同样的尝试 但错误仍然相同。

请帮我解决这个问题。

错误是:

 01-01 22:03:18.038: E/AndroidRuntime(1460):
 java.lang.RuntimeException: An error occured while executing
 doInBackground() 01-01 22:03:18.038: E/AndroidRuntime(1460):   at
 android.os.AsyncTask.done(AsyncTask.java:300) 01-01 22:03:18.038:
 E/AndroidRuntime(1460):    at
 java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 java.util.concurrent.FutureTask.setException(FutureTask.java:222)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 java.util.concurrent.FutureTask.run(FutureTask.java:242) 01-01
 22:03:18.038: E/AndroidRuntime(1460):  at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 java.lang.Thread.run(Thread.java:841) 01-01 22:03:18.038:
 E/AndroidRuntime(1460): Caused by: java.lang.NoClassDefFoundError:
 com.squareup.okhttp.MediaType 01-01 22:03:18.038:
 E/AndroidRuntime(1460):    at
 com.kaverisoft.servicemanager.api.RemoteAPI.<clinit>(RemoteAPI.java:340)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 com.kaverisoft.servicemanager.BusinessCodeActivity$ActivationCodeConfirmation.doInBackground(BusinessCodeActivity.java:314)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 com.kaverisoft.servicemanager.BusinessCodeActivity$ActivationCodeConfirmation.doInBackground(BusinessCodeActivity.java:1)
 01-01 22:03:18.038: E/AndroidRuntime(1460):    at
 android.os.AsyncTask.call(AsyncTask.java:288) 01-01 22:03:18.038:
 E/AndroidRuntime(1460):    at
 java.util.concurrent.FutureTask.run(FutureTask.java:237) 01-01
 22:03:18.038: E/AndroidRuntime(1460):  ... 3 more

我通过制作 Multidex 应用程序解决了这个问题,请参阅 this link 如何制作 multidex 应用程序。