【发布时间】:2020-12-03 14:21:35
【问题描述】:
上下文
我在Android application project 的布局中使用androidx.legacy.widget.Space:
<androidx.legacy.widget.Space
android:layout_width="match_parent"
android:layout_height="@dimen/space_height" />
该类被标记为@Deprecated - 应该使用framework Space class 代替:
// Copied from legacy-support-core-ui-1.0.0-sources.jar/androidx/legacy/widget/Space.java
@deprecated Use framework {@link android.widget.Space} class instead.
查找已弃用 API 的使用情况
我在Android Studio 4.2 Canary 7 中运行Inspect Code... 或Run inspection by Name ... 处理Java 或XML 文件(见屏幕截图) ...
...并在我通过 shell 命令构建时使用编译器参数..
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
...但已不报告了已弃用的Space 类用法。我怎样才能检测到它(以及任何其他此类情况)?
2020 年 8 月 27 日更新
在 Android Studio 中,Java 和 XML 的“已弃用 API 使用 ...”检查均已激活,如设置屏幕截图所示。
相关
- Where can I find a list of Android features that are deprecated by newer features?
- Display classes containing deprecation Android Studio
- How to add -Xlint:unchecked to my Android Gradle based project?
- How do I compile with -Xlint:unchecked?
- Recompile with -Xlint parameters
- Google issue #157676020: Lint doesn't warn about framework deprecated APIs
- Google issue #163080422: lint.xml: synchronize with IDE, allow directory nesting, support configurations, etc
【问题讨论】:
-
很可能是一个错误。请参阅this example 使用 AS 4.0.1 AbsoluteLayout 在 MainActivity.kt 和 activity_main.xml 中被标记为已弃用(删除线),而旧版 Space 仅在 MainActivity.kt 中被标记。 Lint 将 XML 文件中的 AbsoluteLayout 报告为已弃用,但对遗留空间只字未提。 Lint 在 MainActivity.kt 中都保持沉默。两者都在源代码中标有
@Deprecated。 -
谢谢。我链接了上面 Google 问题跟踪器中的两个条目。一个与案例非常匹配,我将这个问题和你的示例项目联系起来。另一个问题是最近讨论 Lint 改进的问题之一。
-
我确实看到了第一个问题 (*6020),但认为它不适用,因为
minSdkVersion不会影响示例应用程序。我认为第二期(*0422)看起来更有希望。
标签: android android-studio gradle androidx android-lint