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

发布于 2025-01-28 04:24:15 字数 1677 浏览 3 评论 0原文

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

执行任务失败':app:MergedEbugresources'。 java.lang.illegalargumentException:无法找到资源文件(d:q \ app \ build \ intermediates \ merged-not-compiled-resources \ debug \ debug \ layout \ layout \ notification_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'


}

Whenever I made any change to an XML file from the project and tried to run it, I got this error-

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.

For running the project I need to do Build > Clean Project every time if I make any changes to XML.

Below is my grade file -

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'


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

萌面超妹 2025-02-04 04:24:16

只需再次按Shift + F10即可。这是最快的方法,耗时少于清洁 - >重建

just press Shift + F10 again.This is the fastest way, less time consuming than Clean -> Rebuild

作妖 2025-02-04 04:24:16

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

显然固定在8.0中。

It's a known issue in AGP, see: https://issuetracker.google.com/issues/206674992

Apparently fixed in 8.0.

一指流沙 2025-02-04 04:24:16

带有JPG图像的再生图标有助于我解决此错误。

Regenerating icons with JPG image helped me fix this error.

不疑不惑不回忆 2025-02-04 04:24:15

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

详细信息:
转到Android Studio中的“构建标签”>然后单击“清洁项目”。
享受!

In short:
"clean project and move on"

Details:
Go to the "build tab" in the android studio > then click on "clean project".
enjoy!

完美的未来在梦里 2025-02-04 04:24:15

我通过几次测试发现,前卫规则是此错误的问题。更改调试的前进规则可以解决该问题。只需要在调试构建类型中设置缩小false即可。

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

I found by several testing that proguard rule is the issue for this error. Changing the proguard rules for debug solves the issue. Just need to set shrinkResources false in the debug buildTypes.

 buildTypes {
        debug {
            minifyEnabled true
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
}
捂风挽笑 2025-02-04 04:24:15

就我而言,重新启动Android Studio是解决方案。

无需设置缩小false。我已经将其设置为True,它的工作原理很好。

Restarting Android Studio was the solution in my case.

There is no need to set shrinkResouces false. I have set it to true and it works completely fine.

零度° 2025-02-04 04:24:15

“清洁项目然后运行应用程序”,这项工作对我来说,您也可以尝试一下

"Clean Project and then run the app", this work for me you can also try this

困倦 2025-02-04 04:24:15

R8是Google的新代码收缩器,当您构建版本APK或AAB时,默认情况下启用了它。要禁用R8,请传递-no-shrink Flag以扑动构建APK或Flutter Build Build appBundle。

要获取.aab(appbundle),

flutter build appbundle --no-shrink

以获取.apk,

flutter build apk --no-shrink

R8 is the new code shrinker from Google, and it’s enabled by default when you build a release APK or AAB. To disable R8, pass the --no-shrink flag to flutter build apk or flutter build appbundle.

To get .aab(appbundle),

flutter build appbundle --no-shrink

To get .apk,

flutter build apk --no-shrink
心的憧憬 2025-02-04 04:24:15

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

选择'文件>无效的caches',然后单击“无效并重新启动”按钮。

Clearing Android Studio's cache resolved the issue for me.

Select 'File > Invalidate Caches' and then click the 'Invalidate and Restart' button.

箜明 2025-02-04 04:24:15

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

Unable to locate resourceFile

,我在项目中删除了.IDEA文件夹。

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

In my case,I build my apk. I click build ->generate signed bundle or APK,
then I get the error

Unable to locate resourceFile

I delete the .idea folder in my project.

enter image description here

Then I build my apk again, it's no more error. it's working for me.

素染倾城色 2025-02-04 04:24:15

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

Build >> Rebuild Project solved my probem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文