Android Eclipse Lint API checks

后端 未结 3 1586
独厮守ぢ
独厮守ぢ 2021-02-10 00:25

Thanks P.T. for what looks like the correct answer to question Building multi-SDK Android apps in Eclipse without losing compile-time checks. However, when I try to use the @Ta

相关标签:
3条回答
  • 2021-02-10 01:04

    The example on the website using the annotation in the middle of the code is simply wrong (or maybe outdated). The declaration of the annotation itself shows that it is only allowed for types, methods and constructors:

    /** Indicates that Lint should treat this type as targeting a given API level, no matter what the
        project target is. */
    @Target({TYPE, METHOD, CONSTRUCTOR})
    @Retention(RetentionPolicy.CLASS)
    public @interface TargetApi {
        /**
         * This sets the target api level for the type..
         */
        int value();
    }
    
    0 讨论(0)
  • 2021-02-10 01:05

    FizzBuzz provided the answer to this in How do you version code in Android without compiler warnings?.

    In addition to the @TargetApi(nn) annotation in the code, you also need to import the definition of that annotation:

    import android.annotation.TargetApi;
    

    For some unknown reason, an import is not required to use the @Override annotation. It would be helpful if the ADT documentation http://tools.android.com/recent/lintapicheck were fixed to eliminate the bogus code example and mention the required import.

    0 讨论(0)
  • 2021-02-10 01:07

    Insert target API annotation just above override annotation

    0 讨论(0)
提交回复
热议问题