vbezhenar
vbezhenar

Reputation: 12316

Android Studio does not recognize android annotations and shows errors in standard libraries

I installed latest Android Studio and generated hello world project (using Java) with empty activity. It builds just fine. But when I navigate to the file from standard android library Activity.java (using Ctrl+Click) it's full of errors. Similar thing happens with other standard android classes. And it's not only aesthetic issue. It seems that android.annotation.Nullable is ignored by IDE. For example I can write getActionBar().hashCode() in my Java code and it does not produce any warnings, despite the fact that method getActionBar() is annotated with android.annotation.Nullable. If I would write getSupportActionBar().hashCode() it would be correctly highlighted with warning, because that method is defined in support library and uses androidx.annotation.Nullable which is recognized (support library files seem to work fine, it's only "core" android library files affected by this issue).

Upvotes: 0

Views: 586

Answers (1)

Ahmad Sattout
Ahmad Sattout

Reputation: 2476

android.annotaion.Nullable is a newly added Android annotation. You'll see it red because it's not publically available, it's restricted to Android AOSP use only.

If you want to use Nullable annotation, you'll have to use the androidx.annotation.Nullable ones.

android.annotaion.Nullable is Android (AOSP) code, while androidx.annotation.Nullable is Jetpack code, it's a Library (first party).

Upvotes: 1

Related Questions