文件使用或覆盖了已过时的 API
2022-03-14 本文已影响0人
雪域红鹰
在编译的过程中出现:
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
解决方案:
1.在在Module的build.gradle中,android节点下,配置如下信息:
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
2.编译后会提醒显示错误
过期API有如下几种情况:
警告: [deprecation] Resources中的getColor(int)已过时
过时:getResources().getColor(R.color.colorAccent)
改为:ContextCompat.getColor(Context,R.color.colorAccent)
警告: [deprecation] Resources中的getDrawable(int)已过时
过时:sContext.getResources().getDrawable(R.drawable.btn)
改为:ContextCompat.getDrawable(sContext,R.drawable.btn)
警告: [deprecation] WebViewClient中的shouldOverrideUrlLoading(WebView,String)已过时
过时:shouldOverrideUrlLoading(WebView view, String url)
改为:
//我们可以通过request.getUrl()来获取url,当前感觉不要改还是好一些
shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
警告: [deprecation] RequestBody中的create(MediaType,File)已过时
过时:RequestBody.create(file,MediaType.parse("image/jpg"))
改为: RequestBody.create(MediaType.parse("image/jpg"),file)
警告: [deprecation] android中的android.os.Build.VERSION.SDK已过时
过时:android.os.Build.VERSION.SDK
改为: android.os.Build.VERSION.SDK_INT