Android Studio 更新后无法解析符号“NonNull" [英] Cannot resolve symbol 'NonNull' after Android Studio update

查看:70
本文介绍了Android Studio 更新后无法解析符号“NonNull"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新了 Android Studio.之后它似乎不再能够解析某些支持注释,例如 @NonNull@Nullable.在更新之前它确实工作得很好.但是,一切仍在编译中,我可以执行代码,但在导入时仍然显示符号无法解析消息.

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. 在 build.gradle 中包含依赖(模块:应用程序):

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

compile 'com.android.support:support-annotations:27.0.0'

  • 我已使缓存失效并重新启动
  • 清理和重建项目
  • (编辑)同步 Gradle
  • 我不知道为什么这不起作用,非常感谢您的帮助.

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

    推荐答案

    自 android api 29 ('targetSdkVersion' 29) 起,com.android.support 已移至 'androidx' 库.

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

    在您的 build.gradle 文件(应用级别)中,依赖项阻止使用...

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

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

    并在您的 .java 文件中使用 import 如下:

    And in your .java files use import as follows:

    import androidx.annotation.NonNull;
    

    再次构建您的项目!

    这篇关于Android Studio 更新后无法解析符号“NonNull"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆