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

Android编译报错mergeDebugResources:无法解析room-common:2.3.0(超时)

问题描述

之前可正常编译运行的Android项目,突然在Android Studio编译时失败,依赖配置如下:

def retrofit_version = '2.9.0'
def room_version = "2.3.0"
def navigation_component = "2.3.5"

//Room
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"

//Navigation component
implementation "androidx.navigation:navigation-runtime-ktx:$navigation_component"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_component"

// ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:1.1.1"

// Firebase
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-crashlytics'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

报错信息:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':module_name:mergeDebugResources'.
> Could not resolve all task dependencies for configuration ':module_name:debugRuntimeClasspath'.
 > Could not resolve androidx.room:room-common:[2.3.0].
 Required by:
     project :module_name > androidx.room:room-runtime:2.3.0
     project :module_name > androidx.room:room-ktx:2.3.0
  > Failed to list versions for androidx.room:room-common.
     > Could not list versions using M2 pattern 'https://jcenter.bintray.com/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier])(.[ext])'.
        > Could not get resource 'https://jcenter.bintray.com/androidx/room/room-common/'.
           > Could not GET 'https://jcenter.bintray.com/androidx/room/room-common/'.
              > Read timed out

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 28s
解决方案
  • 移除JCenter仓库配置:JCenter已停止服务,无法正常提供依赖下载。打开项目根目录的build.gradle文件,找到repositories代码块,删除jcenter(),确保保留google()和mavenCentral(),示例:
    repositories {
        google()
        mavenCentral()
        // 移除jcenter()
    }
    
  • 清理Gradle缓存并重新构建:
    • 方式1:在Android Studio中点击File -> Invalidate Caches...,勾选Invalidate and Restart,等待IDE重启后重新编译项目。
    • 方式2:在项目根目录执行命令行:
      ./gradlew clean build --refresh-dependencies
      
  • 可选:更新依赖版本(推荐):旧版本依赖可能存在兼容性或仓库同步问题,建议将Room、Navigation等依赖更新到稳定新版本,同时将ViewModel依赖从旧的android.arch.lifecycle迁移到androidx.lifecycle体系,示例:
    def room_version = "2.5.0"
    def navigation_component = "2.7.0"
    def lifecycle_version = "2.6.2"
    
    //Room
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    
    //Navigation component
    implementation "androidx.navigation:navigation-runtime-ktx:$navigation_component"
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation_component"
    
    // ViewModel and LiveData
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 02:01:10