【问题标题】:Cannot resolve symbol 'annotation' in Android Studio?无法解析 Android Studio 中的符号“注释”?
【发布时间】:2020-04-21 04:31:30
【问题描述】:

我在我的项目中使用新的 AndroidX,我需要在我的代码中使用 Nullable (@Nullable),但是,当我尝试“import android.support.annotation.Nullable;”时,此命令返回给我: "无法解析符号'注解'"。

这是我在模块级别的 build.gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    // Implementação da autenticação com o servirdor firebase
    implementation 'com.google.firebase:firebase-auth:19.0.0'
    //Implementação da parte visual do Firebase
    implementation 'com.firebaseui:firebase-ui-auth:6.1.0'
    // Implementação de imagens arrendodas
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    // Autenticação geral com o servirdor do Firebase
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    // Autenticação integrada ao google play services
    implementation 'com.google.firebase:firebase-analytics:17.2.0' // Integração ao Google Análises
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    // Integração ao sistema de notifação
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    // Integração com o banco de dados
    implementation 'com.google.firebase:firebase-firestore:21.1.1'
    implementation 'com.google.firebase:firebase-storage:19.1.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    // Integração ao sistema de autenticação de usuário
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.work:work-runtime:2.2.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'

}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

    标签: android android-gradle-plugin build.gradle androidx


    【解决方案1】:

    不要混用 android supportandroidx

    对于 androidx,使用 androidx.annotation.Nullable

    【讨论】:

    • 当我按下“alt+enter”时,发生了自动导入(import android.support.annotation.Nullable),这可能是 Android Studio 版本的“错误”吗?
    • 关于你的 gradle 文件,我不明白为什么 Studio 会导入支持包......听起来有点错误,是的。尝试重新启动 Studio 可能
    • 我做了一个“清理项目”,现在导入正确,我一定是忘记清理项目了。
    【解决方案2】:

    因为我在the official documentation 上找到了信息 您需要迁移到 Androidx。要查找映射到此已弃用类的 AndroidX 类,请参阅Class Mappings上的 AndroidX 支持库

    因此,将android.support.annotation.Nullable 替换为androidx.annotation.Nullable

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-23
      • 2013-11-15
      • 1970-01-01
      • 2015-12-17
      相关资源
      最近更新 更多