Android開發過程中遇到的一些問題和解決方法(持續更新)
混淆後註解丟失
- 解決方法:在混淆的配置文件中添加 -keep class * extends java.lang.annotation.Annotation { *; }
gradle plugn升級到3.0以上錯誤
Error:Cannot choose between the following configurations of project :IMKit:
- 解決方法:implementation project(path: ‘:IMKit’, configuration: ‘default’)
解決Retrofit2上傳中文亂碼問題
- 和服務器統一編碼,基本上都是UTF-8
- 給OKHTTP添加一個Interceptor(攔截器)
.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request.Builder requestBuilder = request.newBuilder();
request = requestBuilder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded;charset=UTF-8"),
URLDecoder.decode(bodyToString(request.body()), "UTF-8")))
.build();
return chain.proceed(request);
}
})