5

Context

I am using the androidx.legacy.widget.Space in a layout in an Android application project:

<androidx.legacy.widget.Space
    android:layout_width="match_parent"
    android:layout_height="@dimen/space_height" />

The class is marked as @Deprecated - one should use the framework Space class instead:

// 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.

Finding usage of deprecated APIs

I ran Inspect Code... or Run inspection by Name ... for Java or XML files (see screenshots) in Android Studio 4.2 Canary 7 ...

Deprecated API usage (Java | Code maturity)

Deprecated API usage in XML

... and use the compiler arguments when I build via shell command ..

options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"

... but the deprecated Space class usage is not reported. How can I detect it (and any other such cases)?

Update 27.08.2020

In Android Studio both the "Deprecated API usage ..." Inspections for Java and XML are activated as shown in the Setting screenshot.

Deprecated API usage

Related

JJD
  • 50,076
  • 60
  • 203
  • 339
  • 1
    Most likely a bug. See [this example](https://github.com/Cheticamp/DeprecationProblem) using AS 4.0.1 AbsoluteLayout is flagged as deprecated (strike-through) in MainActivity.kt and in activity_main.xml while the legacy Space is only flagged in MainActivity.kt. Lint reports the AbsoluteLayout in the XML file as deprecated but says nothing about the legacy Space. Lint is silent on both in MainActivity.kt. Both are flagged with `@Deprecated` in the source. – Cheticamp Aug 27 '20 at 19:43
  • Thank you. I linked two entries from the Google issue tracker above. One pretty much matches the case and I linked this question and your sample project there. The other issue is one of the recent issues where Lint improvements are discussed. – JJD Aug 28 '20 at 12:54
  • I did see the first issue (*6020) but didn't think it applied since the `minSdkVersion` didn't effect the sample app. I think the second issue (*0422) looks more promising. – Cheticamp Aug 28 '20 at 13:31

1 Answers1

0

Searching for Deprecated API Usage in XML by clicking Analyze -> Run Inspectinon By Name ->type Deprecated API Usage should fetch all the deprecated instances in XML files. Could you paste the screenshot of your results returned by searching by name?
Or try this Manually Run Inspections by setting scope as whole project. This will also fetch the deprecated instances. For Java classes search for Java->Code Maturity->Deprecated API usage. and for XML search for XML->Deprecated API usage in XML.
Last option is to search androidx.legacy.widget.Space in Find in path. Press Ctrl+Shift+F and search for androidx.legacy.widget.Spacethroughout project or you could even add a file mask such as only xml.

Nadeem Shaikh
  • 1,160
  • 9
  • 17
  • The result of running the `Deprecated API usage in XML` inspection scoped on the particular XML file is a popup which states: `No suspicious code found. 1 file processed ..`. This should not be the case to my understanding. - Searching (find) manually does not make sense here. Imagine that you don't know which class/method is deprecated. How can you search for it without knowing its name? It is a hen/egg problem. – JJD Aug 27 '20 at 13:47
  • The reason I told to go for manual search was you had the name for the class androidx Space class. Don't know why your studio showing No suspicious code found error. – Nadeem Shaikh Aug 27 '20 at 16:41