importing NotNull or Nullable and Android Studio won't compile

I guess, the right way is using original JetBrains library from MavenCentral repository in your build.gradle dependencies (latest available version in this example):

dependencies {
    implementation 'com.intellij:annotations:+@jar'
    ...
}

You can also use android's own @NonNull & @Nullable:

  • Add the following to build.gradle:

    dependencies {
        ...
        // For @Nullable/@NonNull
        compile 'com.android.support:support-annotations:+'
    }
    
  • Go to File / SettingProject SettingsInspections and search for "nullable".

    In Constant conditions & exceptions and @NotNull/@Nullable problems, click Configure annotations and select Android's annotations.

    You may also want to check out Suggest @Nullable annotations… under Constant conditions & exceptions, or possibly tweak other options.


For using Android support anotation like - @Nullable, @NonNull etc.. In your project must be imported android support annotations library. Just add this line to dependensies in gradle file

dependencies { compile 'com.android.support:support-annotations:+' }

And import package to class.
For using @Nullable annotation:

import android.support.annotation.Nullable;

For @NonNull

import android.support.annotation.NonNull;

More info you can find here Android developers