首页 > 解决方案 > 合并资源时无法编译值文件(来自两个不同依赖项的文件中的重复值

问题描述

在解决了其中存在的所有问题并找到导入所有依赖项的方法后,我从 GitHub 下载了一个旧的 android 项目build.gradle,我收到以下错误。

> Task :app:mergeDebugResources
C:\Users\admin\.gradle\caches\transforms-2\files-2.1\7160c6b9fdb2bc1e41d9bd715d01fdc2\appcompat-1.3.0\res\values\values.xml:1711:4: Duplicate value for resource 'attr/background' with config 'DEFAULT' and product ''. Resource was previously defined here: C:\Users\admin\.gradle\caches\transforms-2\files-2.1\413908c8957c32f488ee44857e65d202\jetified-actionbarsherlock-4.4.0\res\values\values.xml:5:4: .
C:\Users\admin\.gradle\caches\transforms-2\files-2.1\413908c8957c32f488ee44857e65d202\jetified-actionbarsherlock-4.4.0\res\values\values.xml:27:4: Duplicate value for resource 'attr/navigationMode' with config 'DEFAULT' and product ''. Resource was previously defined here: C:\Users\admin\.gradle\caches\transforms-2\files-2.1\7160c6b9fdb2bc1e41d9bd715d01fdc2\appcompat-1.3.0\res\values\values.xml:1711:4: .
C:\Users\admin\.gradle\caches\transforms-2\files-2.1\413908c8957c32f488ee44857e65d202\jetified-actionbarsherlock-4.4.0\res\values\values.xml:232:4: Duplicate value for resource 'attr/itemBackground' with config 'DEFAULT' and product ''. Resource was previously defined here: C:\Users\admin\.gradle\caches\transforms-2\files-2.1\2730d74d200c17936a122ce975a9aa70\material-1.3.0\res\values\values.xml:3634:4: .
C:\Users\admin\.gradle\caches\transforms-2\files-2.1\413908c8957c32f488ee44857e65d202\jetified-actionbarsherlock-4.4.0\res\values\values.xml:296:4: Duplicate value for resource 'attr/actionBarSize' with config 'DEFAULT' and product ''. Resource was previously defined here: C:\Users\admin\.gradle\caches\transforms-2\files-2.1\7160c6b9fdb2bc1e41d9bd715d01fdc2\appcompat-1.3.0\res\values\values.xml:1979:4: .

> Task :app:mergeDebugResources FAILED
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
   > Resource compilation failed. Check logs for details.

* 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.

有人可以帮我解决这个问题吗?

这是我的build.gradle文件(:app),

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.madmicroproject"
        minSdkVersion 18
        targetSdkVersion 30
        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 {
    def multidex_version = "2.0.1"
    implementation "androidx.multidex:multidex:$multidex_version"
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    implementation "commons-io:commons-io:2.9.0"
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    implementation 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    implementation group: 'eu.chainfire', name: 'libsuperuser', version: '1.1.0.202004101746'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.volley:volley:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

如果需要更多信息,请告诉我。

标签: androidgradle

解决方案


推荐阅读