java.lang.NoClassDefFoundError:解析失败:Lcom / squareup / okhttp / OkUrlFactory

时间:2018-01-24 08:44:38

标签: android retrofit

我想在改造中设置超时

我添加编译' com.squareup.okhttp:okhttp:1.6.0' 在Retrofit中设置超时

应用程序崩溃并显示错误

java.lang.NoClassDefFoundError:解析失败:Lcom / squareup / okhttp / OkUrlFactory

这是我的代码

  Gson localGson = new GsonBuilder().create();

    final OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setReadTimeout(300, TimeUnit.SECONDS);
    okHttpClient.setConnectTimeout(300, TimeUnit.SECONDS);


    this.uploadService = ((IndentSyncService)new RestAdapter.Builder()
            .setEndpoint(URL)
            .setConverter(new GsonConverter(localGson))
            .setClient(new OkClient(okHttpClient))//on this line app gets crash
            .setRequestInterceptor(new RequestInterceptor()
            {
                public void intercept(RequestInterceptor.RequestFacade requestFacade)
                {
                    //By adding header to the request will allow us to debug into .Net code in server
                    if (URL.contains("10.0.2.2")) {
                        requestFacade.addHeader("Host", "localhost");
                    }
                }
            })
            .build().create(IndentSyncService.class));

我的傻瓜

compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support:cardview-v7:26.+'

compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp:1.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'

1 个答案:

答案 0 :(得分:0)

添加

compile 'com.squareup.okhttp:okhttp-urlconnection:1.6.0'

来源:https://github.com/square/okhttp/issues/879