Android Studio 3.1.2中:app:mergeDebugResources任务执行失败求助
:app:mergeDebugResources Error in Android Studio 3.1.2 Hey there, let's work through this :app:mergeDebugResources error you're hitting. Based on your setup details and build configs, here are actionable steps to resolve it:
1. Fix the Gradle Plugin Version in Your Root Build.gradle
You’re using a wildcard + for the Gradle plugin classpath, which can cause issues in offline mode—Android Studio can’t pull the latest matching version when offline. Android Studio 3.1.2 is designed to work with Gradle plugin 3.1.2, so update your root build.gradle:
buildscript { repositories { google() jcenter() } dependencies { // Replace the wildcard with the exact matching version classpath 'com.android.tools.build:gradle:3.1.2' } }
Since you’ve already confirmed Gradle 4.4 works with your Studio version, this exact plugin version will sync smoothly offline.
2. Check for Corrupted/Invalid Resource Files
The mergeDebugResources error almost always ties to issues in your res/ directory. Here’s what to verify:
- Image assets: Make sure all images (PNG, JPG, etc.) in
drawable/ormipmap/aren’t corrupted. Try re-exporting them from your design tool if needed. - XML syntax: Scan layout, values, or menu XML files for typos, unclosed tags, or invalid characters (like unescaped quotes in strings).
- Filename issues: Avoid spaces, special characters, or non-ASCII characters in resource filenames (e.g., replace
背景图.pngwithbackground.png). - Duplicate resources: Ensure you don’t have identical resource names across different resource directories (e.g., same drawable name in
drawable-hdpianddrawable-xhdpiwith conflicting files).
3. Clean and Invalidate Caches
Offline mode can sometimes leave stale cache files that cause resource merging issues:
- Go to File > Invalidate Caches / Restart
- Select Invalidate and Restart to clear all cached data and restart Android Studio
- After restart, run Build > Clean Project followed by Build > Rebuild Project
4. Specify the Correct Build Tools Version
Since you’re using compileSdkVersion 27, make sure you’ve installed SDK Build Tools 27.0.3 (the stable version for API 27) in your SDK Manager. Then add it explicitly to your app’s build.gradle:
android { compileSdkVersion 27 buildToolsVersion "27.0.3" // Add this line if missing ... }
Try these steps one by one—most likely the Gradle plugin version or a corrupted resource is the root cause here.
内容的提问来源于stack exchange,提问作者kia me




