2

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

import android.annotation.IntDef;
import android.annotation.NonNull;

keep getting an error related to this line like:

the import android.annotation cannot be resolved

Any suggestion will be appreciated

3 Answers3

1

I think it would be better if you work with the support annotations: add this dependency to your project and see if it works:

compile 'com.android.support:support-annotations:24.2.0'
1

accourding to this answer you can use 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

max
  • 5,963
  • 12
  • 49
  • 80
0

I had faced the same problem and came across this question but was not answered. I could resolve this issue by following steps mentioned here.
After this, You shall sync the project with Gradle files.
Note: You may not find the same annotation path
e.g. import android.annotation.NonNull; --> import androidx.annotation.Nullable;