37

I'm trying to run a sample android code in eclipse, but when I try:

import android.annotation.SuppressLint;

I keep getting an error related to this line like:

the import android.annotation cannot be resolved

I will appreciate if someone can help me with this.

Alfergon
  • 5,463
  • 6
  • 36
  • 56
m0j1
  • 4,067
  • 8
  • 31
  • 54

4 Answers4

51

Wich API do you Refered in your project.

Because

android.annotation.SuppressLint - it's since Added in API level 16

http://developer.android.com/reference/android/annotation/SuppressLint.html

You need do next

You project rigth mouse click->Properties and check next picture for you select Project Build Target for API Level >=16

enter image description here

Dmitry Nelepov
  • 7,246
  • 8
  • 53
  • 74
  • Thanks , seems like that's the problem . but when I open my SDK manager , it doesn't give me any option to upgrade to API level more than 13 . do I have to download my sdk again ? – m0j1 Feb 14 '13 at 09:28
  • 2
    Yes, you need run android sdk manager to chekout updates. After that you must run Eclipse Update software for ADT Plugin updates. – Dmitry Nelepov Feb 14 '13 at 15:21
  • This issue also appeared when importing libraries, for example the Facebook SDK. For some reason it was set to build at a lower level than my main project. I had an error on the libproject only, not my main app and had to change the build path just for the SDK for it to work. – Rarw Sep 02 '15 at 01:29
21

As Artem suggested, you may need to include the annotations.jar file into your project, but note that there are two annotations.jar files in your Android SDK:

android-sdk/tools/support/annotations.jar - Which includes the following annotations:

  • SuppressLint
  • TargetApi

android-sdk/extras/android/support/annotations/annotations.jar - Which includes many other annotations:

  • AnimRes
  • AnimatorRes
  • AnyRes
  • ArrayRes
  • AttrRes
  • BoolRes
  • ColorRes
  • DimenRes
  • DrawableRes
  • FractionRes
  • IdRes
  • IntDef
  • IntegerRes
  • InterpolatorRes
  • LayoutRes
  • MenuRes
  • NonNull
  • Nullable
  • PluralsRes
  • RawRes
  • StringDef
  • StringRes
  • StyleRes
  • StyleableRes
  • XmlRes
TheIT
  • 11,919
  • 4
  • 64
  • 56
12

In your android-sdk/tools/support/annotations.jar, it contains the android.annotation.SuppressLint and android.annotation.TargetApi's definition.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
Artem
  • 121
  • 1
  • 3
2

Dmitry Nelepov's answer is correct, though sometimes your project is already on the desired Project Build Target (this happened in my case). Simply switch the build case to a different one, press "OK", then redo the steps to set it back to the right Project Build Target.

Bart Burg
  • 4,786
  • 7
  • 52
  • 87