Can I mark a resource in my Android project as deprecated?

I have an android library for which I would like to mark some resources as deprecated. Drawables, sizes, durations ... I read somewhere that I can add deprecated = "deprecated" to the resource definition, but it doesn't do anything.

In Android R, you can see things like

@java.lang.Deprecated
public static final int autoText = 16843114;
      

Run codeHide result


I'm trying to create something like this by editing durations.xml, values.xml or even public.xml ...

Thank!

+3


source to share


2 answers


Short answer: Impossible.

Tags

@deprecated

are used by android source inside comments as seen in fw / base core / res / values ​​/attrs.xml (see line 3427 for autoText as mentioned in original post), in fw / base core / res / values /public.xml and elsewhere throughout the project, but it seems that the build tools used to build apps are just skipping all comments, meaning that annotation tags are also skipped in the process where this method fails.



Example using deprecation annotations based on Android source:

<!-- {@deprecated Use foobar instead.} -->
<string name="foo">abc</string>
<string name="foobar">abcd</string>

      

+3


source


I just add the TODO statement. It does not indicate a resource, but the DOC TODO keyword appears in Git and as labels in the gutter. Hopefully these warnings are enough to prevent you and others from using it.

But not always. As we know, @Deprecated is essentially a stop-space until something is really deleted permanently and the code is cleaned up properly.



Here is an example shape.xml file that I no longer use (and want @Deprecate).

<?xml version="1.0" encoding="utf-8"?>
<!--
    Border around card elements.  For now this is used only within the
    cards of the Questionnaire RecyclerView.

    TODO:  This file is obsolete. Use CardView instead.
-->
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="@dimen/tiny_card_margin"
        android:color="@color/colorPrimaryDark" />
    <solid
        android:color="@android:color/white" />
    <corners
        android:radius="4dp" />
</shape>

      

+1


source







All Articles