You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio:如何修复“Cannot resolve symbol 'core'”等符号解析错误

解决Android Studio中无法解析NonNull、core、NotificationCompat符号的问题

具体解决步骤

1. 确认依赖添加位置是否正确

确保你是在模块级的build.gradle(通常是app/build.gradle)文件中添加的依赖,而非项目根目录的build.gradle——很多人会搞错这个文件位置,导致依赖未生效。

2. 同步并重建项目

  • 点击Android Studio右上角的「Sync Project with Gradle Files」按钮,同步依赖配置。
  • 依次执行Build > Clean Project和Build > Rebuild Project,彻底清理编译缓存后重新构建。

3. 检查AndroidX配置完整性

确保项目已完全迁移到AndroidX,在gradle.properties文件中添加以下配置:

android.useAndroidX=true
android.enableJetifier=true

Jetifier会自动将旧Support库依赖转换为AndroidX版本,避免版本冲突。

4. 调整依赖版本(可选)

版本不兼容也可能引发解析问题,可尝试替换为稳定兼容的版本,同时移除未用到的依赖:

dependencies {
    implementation 'androidx.annotation:annotation:1.7.0'
    implementation 'androidx.core:core:1.12.0'
    implementation 'androidx.core:core-ktx:1.12.0'
}

比如你添加的androidx.mediarouter:mediarouter如果没用到,直接删掉即可。

5. 修正代码语法问题

你的代码片段中NotificationCompat.Builder的初始化没有完成,必须调用.build()方法才能生成Notification对象,语法不完整也会导致IDE无法正确解析符号,补充完整代码:

Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
        .setContentTitle("Foreground Service")
        // 补充其他必要属性,比如setContentText、setSmallIcon等
        .setSmallIcon(R.drawable.ic_notification)
        .build();

6. 清理Android Studio缓存

如果以上步骤都无效,尝试清理IDE缓存:
点击File > Invalidate Caches...,选择Invalidate and Restart,重启Android Studio后再检查问题。


内容的提问来源于stack exchange,提问作者jdevp2

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 13:07:04