Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol 'NonNull' after Android Studio update

Tags:

I recently updated Android Studio. Afterwards it seems to no longer being able to resolve some support annotations, such as @NonNull or @Nullable. It did work just fine before updating. However, everything is still compiling and I am able to execute Code, but still it shows the symbol cannot be resolved message at my imports.

What I have already tried so far:

  1. Included the dependency in build.gradle (Module: Application):

    compile 'com.android.support:support-annotations:27.0.0' 
  2. I have invalidated Caches and restarted
  3. Cleaning and rebuilding the project
  4. (Edit) Synched Gradle

I have no idea why this is not working and would really appreciate your help.

like image 507
Andi Z. Avatar asked May 22 '18 14:05

Andi Z.


1 Answers

As of android api 29 ('targetSdkVersion' 29) com.android.support has been moved to 'androidx' library.

In your build.gradle file(app level), dependencies block use...

dependencies{      ...     implementation 'androidx.annotation:annotation:1.1.0'  } 

And in your .java files use import as follows:

import androidx.annotation.NonNull; 

Again build your project!

like image 169
userAbhi Avatar answered Sep 19 '22 13:09

userAbhi