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

制作天气App时Gradle同步报错:Retrofit依赖解析失败求助

解决Gradle同步Retrofit依赖解析失败问题

问题根源

你的依赖配置存在两处关键错误:

  • Retrofit的包名拼写错误:正确包名是com.squareup.retrofit2,而非com.square.retrofit2(少了一个up)
  • Retrofit核心依赖的冒号前多了空格,且最后一行Gson依赖末尾有多余的反引号

修正后的完整依赖代码

dependencies {
    implementation ("androidx.core:core-ktx:1.10.1")
    implementation ("androidx.appcompat:appcompat:1.6.1")
    implementation ("com.google.android.material:material:1.9.0")
    implementation ("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation ("androidx.gridlayout:gridlayout:1.0.0")
    testImplementation ("junit:junit:4.13.2")
    androidTestImplementation ("androidx.test.ext:junit:1.1.5")
    androidTestImplementation ("androidx.test.espresso:espresso-core:3.5.1")
    implementation ("com.airbnb.android:lottie:6.1.0")
    implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
    implementation ("com.squareup.retrofit2:retrofit:2.9.0")
    implementation ("com.google.code.gson:gson:2.10.1")
}

若仍无法解决的额外排查步骤

  • 检查项目根目录下的build.gradle文件,确保已添加mavenCentral()仓库:
    repositories {
        google()
        mavenCentral()
    }
    
  • 执行缓存清理:点击Android Studio顶部菜单栏的File -> Invalidate Caches...,勾选Invalidate and Restart选项重启IDE

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 11:03:22