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);
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章