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

问题描述 投票:0回答:11

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

任务“:app:mergeDebugResources”执行失败。 java.lang.IllegalArgumentException:无法找到资源文件(D:Q pp uild\intermediates\merged-not-compiled-resources\debug\layout otification_action.xml) 在源集中。

为了运行项目,如果我对 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'


}
android android-xml
11个回答
34
投票

简而言之: “清理项目并继续前进”

详情: 转到 android studio 中的“构建选项卡”> 然后单击“清理项目”。 享受吧!


22
投票

我通过多次测试发现混淆器规则是导致此错误的问题。更改调试的混淆规则可以解决该问题。只需要在 debug buildTypes 中设置

shrinkResources false
即可。

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

8
投票

“清理项目,然后运行应用程序”,这对我有用,你也可以尝试这个


7
投票

重新启动 Android Studio 是我案例的解决方案。

无需设置

shrinkResouces false
。我已将其设置为 true 并且工作完全正常。


2
投票

R8 是 Google 推出的新代码压缩器,当您构建发布 APK 或 AAB 时,它会默认启用。要禁用 R8,请将 --no-shrink 标志传递给 flutter build apk 或 flutter build appbundle。

获取.aab(appbundle),

flutter build appbundle --no-shrink

要获取.apk,

flutter build apk --no-shrink

1
投票

就我而言,我构建了我的 apk。我点击构建->生成签名包或APK, 然后我得到错误

Unable to locate resourceFile

我删除了项目中的 .idea 文件夹。

enter image description here

然后我再次构建我的apk,不再有错误。它对我有用。


0
投票

清除 Android Studio 的缓存解决了我的问题。

选择“文件 > 使缓存无效”,然后单击“无效并重新启动”按钮。


0
投票

构建 >> 重建项目解决了我的问题


0
投票

只需再次按 Shift + F10。这是最快的方法,比 Clean -> Rebuild 耗时更少


0
投票

这是 AGP 中的一个已知问题,请参阅:https://issuetracker.google.com/issues/206674992

显然已在 8.0 中修复。


0
投票

使用 JPG 图像重新生成图标帮助我修复了这个错误。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.