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

Android Studio构建报错:无法解析legacy-support-core-utils-1.0.0.jar

解决Android Studio中mergeDebugJavaResource无法解析legacy-support-core-utils-1.0.0的问题

错误信息

mergeDebugJavaResource
Could not resolve legacy-support-core-utils-1.0.0.jar (androidx.legacy:legacy-support-core-utils:1.0.0)

我的Gradle配置

根目录build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        maven { url 'https://maven.google.com' }
        mavenCentral()
        maven { url 'https://jitpack.io' }
     }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        maven { url 'https://maven.google.com' }
        mavenCentral()
        maven { url 'https://jitpack.io' }
     }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块build.gradle

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.i_e_commerce.Moodlia"
        minSdkVersion 16
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
//    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.intuit.ssp:ssp-android:1.1.0'
    implementation 'androidx.preference:preference:1.1.1'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
//    implementation 'com.kovachcode:timePickerWithSeconds:1.0.1'
    implementation 'io.github.ShawnLin013:number-picker:2.4.13'
    implementation 'com.github.chrisbanes:PhotoView:2.0.0'

    implementation 'com.github.f0ris.sweetalert:library:1.6.2'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
}

已尝试更换依赖版本、使用VPN,问题未解决。


排查与解决方案

1. 定位依赖传递来源

注释掉legacy-support-v4后仍出现该错误,说明有其他依赖间接引入了legacy-support-core-utils。执行以下命令查看完整依赖树:

./gradlew app:dependencies

搜索legacy-support-core-utils,找到触发该依赖的库,可针对性排除或调整。

2. 简化仓库配置

google()仓库已经包含了maven.google.com,重复配置可能导致解析冲突。修改根build.gradle的仓库部分:

buildscript {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
     }
    // 其余内容不变
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
     }
}

3. 强制指定依赖版本

直接在模块build.gradle的dependencies中添加该依赖的明确版本,覆盖传递依赖的版本:

implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
// 若1.0.0仍无法解析,尝试兼容版本1.0.1
// implementation 'androidx.legacy:legacy-support-core-utils:1.0.1'

4. 清理Gradle缓存

缓存损坏是常见的依赖解析失败原因,执行以下操作:

  • 打开Android Studio,点击File -> Invalidate Caches...,选择Invalidate and Restart
  • 手动删除本地缓存目录:
    • Windows:C:\Users\<你的用户名>\.gradle\caches
    • macOS/Linux:~/.gradle/caches

5. 升级Gradle版本兼容性

当前Gradle插件4.1.3对compileSdk 31的支持有限,建议升级到适配版本:
修改根build.gradle的classpath:

classpath 'com.android.tools.build:gradle:7.0.4'

同时修改gradle/wrapper/gradle-wrapper.properties中的下载链接:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 16:05:40