每当我对项目中的 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 studio 中的“构建选项卡”> 然后单击“清理项目”。 享受吧!
我通过多次测试发现混淆器规则是导致此错误的问题。更改调试的混淆规则可以解决该问题。只需要在 debug buildTypes 中设置
shrinkResources false
即可。
buildTypes {
debug {
minifyEnabled true
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
“清理项目,然后运行应用程序”,这对我有用,你也可以尝试这个
重新启动 Android Studio 是我案例的解决方案。
无需设置
shrinkResouces false
。我已将其设置为 true 并且工作完全正常。
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
清除 Android Studio 的缓存解决了我的问题。
选择“文件 > 使缓存无效”,然后单击“无效并重新启动”按钮。
构建 >> 重建项目解决了我的问题
只需再次按 Shift + F10。这是最快的方法,比 Clean -> Rebuild 耗时更少
这是 AGP 中的一个已知问题,请参阅:https://issuetracker.google.com/issues/206674992
显然已在 8.0 中修复。
使用 JPG 图像重新生成图标帮助我修复了这个错误。