标签 "Android" 下的文章

问题:安卓build时报错Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://sch

解决: 在两个地方理性gradle版本

方法:

更改项目 build.gradle 文件

将 classpath 'com.android.tools.build:gradle:4.1.3'
改为 classpath 'com.android.tools.build:gradle:7.0.2'

更改项目 gradle-wrapper.properties 文件

将 distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
改为 distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

阅读全文

问题:android项目build时报错DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding

解决: DSL元素的android.viewBinding。已被替换为“android.buildFeatures.viewBinding”,它将在5.0版的Android Gradle插件中被删除。

方法:

在app下的 build.gradle 文件中注释掉 viewBinding

buildFeatures {
    viewBinding true
}
//    viewBinding {
//        enabled = true
//    }

阅读全文

问题: okhttp的post传递参数如何写?

方法:

Post请示,传递json格式数据

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
     RequestBody body = RequestBody.create(JSON, json);
      Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
//同步
      Response response = client.newCall(request).execute();
    f (response.isSuccessful()) {
        return response.body().string();
    } else {
        throw new IOException("Unexpected code " + response);
    }
}

阅读全文