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

Android Studio中Cannot resolve symbol 'Retrofit'问题求助

解决Retrofit2 "Cannot resolve symbol 'Retrofit'" 错误

针对你遇到的问题,给你几个针对性的排查和解决步骤:

  • 检查仓库配置
    确保项目已配置mavenCentral仓库(Retrofit托管在此):
    新版Android Studio(Arctic Fox及以上)在settings.gradle中:

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral() // 必须包含这一行
        }
    }
    

    旧版项目在根目录build.gradle的allprojects块中:

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
  • 确认依赖添加位置和写法
    必须在app模块的build.gradle(Module级别)的dependencies块中添加Retrofit依赖,正确示例:

    dependencies {
        // Retrofit核心依赖
        implementation 'com.squareup.retrofit2:retrofit:2.9.0'
        // 若需Gson解析响应,额外添加Converter
        implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    }
    

    注意:不要把依赖加到buildscript的dependencies里,那是配置插件的地方,不是依赖库的位置。

  • 彻底清理缓存
    除常规操作外,试试更彻底的缓存清理:
    打开File -> Invalidate Caches...,勾选Invalidate and Restart,等待Android Studio重启并重新构建项目。

  • 检查版本兼容性
    确保你的compileSdkVersion不低于21(Retrofit 2.9.0最低要求),如果低于这个版本,要么提升compileSdkVersion,要么降级Retrofit到兼容的版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 17:02:44