okhttp3x java.lang.nosuchmethoderror: no static method create

項目中一直使用的okhttp版本是3.x的版本,這次在某個module中使用了4.x的okhttp後,運行報錯。

java.lang.nosuchmethoderror: no static method create(ljava/lang/string;lokhttp3/mediatype;)lokhttp3/requestbody; in class lokhttp3/requestbody; or its super classes (declaration of ‘okhttp3.requestbody’ appears in /data/app/com.best.android.laiqu-f4lstkfdirghpypawepjyq==/base.apk!classes4.dex)
在這裏插入圖片描述

大致意思是說沒有這個靜態方法,看了下3.xrequestbody這部分的代碼被4.x方法廢棄。4.x中的contentType和content參數相反,再加上,主項目中使用的是3.x版本,其他module會默認降級到3.x,所以報錯,記錄下

 /**
   * Returns a new request body that transmits {@code content}. If {@code contentType} is non-null
   * and lacks a charset, this will use UTF-8.
   */
  public static RequestBody create(@Nullable MediaType contentType, String content) {
    Charset charset = Util.UTF_8;
    if (contentType != null) {
      charset = contentType.charset();
      if (charset == null) {
        charset = Util.UTF_8;
        contentType = MediaType.parse(contentType + "; charset=utf-8");
      }
    }
    byte[] bytes = content.getBytes(charset);
    return create(contentType, bytes);
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章