java.lang.NoClassDefFoundError:解析失败:Lokio / Buffer;

时间:2016-05-03 03:28:07

标签: retrofit

当我使用改造时。我得到了异常java.lang.NoClassDefFoundError:失败的解析:Lokio / Buffer;我使用okhttpclient来设置retrofit.get的标头userList是一个post方法,我需要发送body在请求中。

private void getUserList(int startIndex){
    final JSONObject audienceObj = ProtocolHelper.getProtocolUtils(mContext).getUserlistJsonObj(mRoomData.mUid, mRoomData.mRoomId, startIndex);
    OkHttpClient okClient = new OkHttpClient.Builder()
    .addInterceptor(
        new Interceptor() {
          @Override
          public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
                Request original = chain.request();

                // Request customization: add request headers
                Request.Builder requestBuilder = original.newBuilder()
                        .header("sessionId", CommonData.getUserInfo(mContext).sessionId);
                Request request = requestBuilder.build();
                return chain.proceed(request);
            }
        })
    .build();


    String baseUrl = ProtocolUtils.BASE_URL+"/";
    Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(GsonConverterFactory.create())
    .client(okClient)
    .build();

    String audienceUrl = ProtocolHelper.getProtocolUtils(mContext).getProtocolUrl(ProtocolUtils.PROTOCOL_MSG_ID_MEMBER_LIST);
    AudienceInterface audienceInterface = retrofit.create(AudienceInterface.class);
    Call<String> call = audienceInterface.getAudienceList(audienceUrl,audienceObj);
    call.enqueue(new Callback<String>() {
        @Override
        public void onResponse(Call<String> call, Response<String> response) {
            Log.d(TAG, "onResponse");
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            Log.d(TAG, "onFailure"+t.getMessage());
        }
    });
}

public interface AudienceInterface {

@POST("{url}")
Call<String>getAudienceList(@Path("url") String url,@Body JSONObject boder);

}

log t.getMessage是:java.lang.NoClassDefFoundError:解析失败:Lokio / Buffer;

2 个答案:

答案 0 :(得分:4)

我通过添加以下内容解决了该问题:

implementation 'com.squareup.okio:okio:2.1.0'

在build.gradle(模块:app)下的依赖项中。

答案 1 :(得分:3)

好吧.~我上次也发现了这个错误 由此:
NoClassDefFoundError:解析失败:Lokio / Buffer
你可能会失去另一个jar lib - Okio 您可以从github下载jar文件:
https://github.com/square/okio
并将此lib附加到您的项目中。