任务 ':app:mergeDebugResources' 执行失败,无法在源集中找到资源文件

Execution failed for task ':app:mergeDebugResources' , Unable to locate resourceFile in source-sets

每当我对项目中的 XML 文件进行任何更改并尝试 运行 它时,我都会收到此错误 -

Execution failed for task ':app:mergeDebugResources'. java.lang.IllegalArgumentException: Unable to locate resourceFile (D:Q\app\build\intermediates\merged-not-compiled-resources\debug\layout\notification_action.xml) in source-sets.

对于 运行 项目,如果我对 XML.

进行任何更改,我每次都需要执行构建 > 清理项目

下面是我的成绩档案-

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "xxxxx"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            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.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.github.ybq:Android-SpinKit:1.4.0'


}

我通过多次测试发现混淆规则是导致此错误的原因。更改调试的 proguard 规则解决了这个问题。只需要在 debug buildTypes 中设置 shrinkResources false.

 buildTypes {
        debug {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
}