java.lang.RuntimeException Caused by: retrofit.RetrofitError: com.squareup.okhttp.Request$Builder

java.lang.RuntimeException Caused by: retrofit.RetrofitError: com.squareup.okhttp.Request$Builder

我正在使用 RetroFit 版本 1.9.0 发出 PUT 请求以将图像添加到某个位置,同时还使用访问 cookie,但在图像传输正确开始之前,我收到错误:

09-14 13:35:12.718  21896-22689/com.company.app E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #5
java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
 Caused by: retrofit.RetrofitError: com.squareup.okhttp.Request$Builder
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
        at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
        at $Proxy10.addPicture(Native Method)
        at com.company.app.parser.ImageSender$BackgroundTask.doInBackground(ImageSender.java:70)
        at com.company.app.parser.ImageSender$BackgroundTask.doInBackground(ImageSender.java:39)
        at android.os.AsyncTask.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
 Caused by: java.lang.NoClassDefFoundError: com.squareup.okhttp.Request$Builder
        at retrofit.client.OkClient.createRequest(OkClient.java:57)
        at retrofit.client.OkClient.execute(OkClient.java:53)
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
        at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
        at $Proxy10.addPicture(Native Method)
        at com.company.app.parser.ImageSender$BackgroundTask.doInBackground(ImageSender.java:70)
        at com.company.app.parser.ImageSender$BackgroundTask.doInBackground(ImageSender.java:39)
        at android.os.AsyncTask.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)

请求是这样的:

private class BackgroundTask extends AsyncTask<TypedFile, Void, JSONObject> {

    RestAdapter restAdapter;

    RequestInterceptor requestInterceptor = new RequestInterceptor() {
        @Override
        public void intercept(RequestInterceptor.RequestFacade request) {
            request.addHeader("Cookie", CookieJar.openJar().getCookie());
        }
    };

    @Override
    protected void onPreExecute() {
        restAdapter = new RestAdapter.Builder()
                .setEndpoint(BasicData.BASE_URL)
                .setRequestInterceptor(requestInterceptor)
                .setLogLevel(RestAdapter.LogLevel.FULL)
                .build();
    }

    @Override
    protected JSONObject doInBackground(TypedFile... params) {
        IApiMethods methods = restAdapter.create(IApiMethods.class);
        JSONObject response = methods.addPicture(CardManager.getInstance().getCurrentCard().getId(), params[0]);

        return response;
    }

    @Override
    protected void onPostExecute(JSONObject response) {
        if (response != null) {
            parserReceiver.parseSuccess(null, parserName);
        }
    }
}

资料

public interface IApiMethods {

  @Headers({
        "Connection: Keep-Alive"
  })
  @Multipart
  @PUT("/0.1/ideas/{id}/picture")
  JSONObject addPicture(@Path("id") String ideaId, @Part("file") TypedFile picture);
}

我认为 Retrofit 可能需要 OkHttp 依赖项

compile 'com.squareup.okhttp:okhttp:2.2.0'