You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Android Studio 3.1.2中:app:mergeDebugResources任务执行失败求助

Fix for :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/ or mipmap/ 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 背景图.png with background.png).
  • Duplicate resources: Ensure you don’t have identical resource names across different resource directories (e.g., same drawable name in drawable-hdpi and drawable-xhdpi with conflicting files).

3. Clean and Invalidate Caches

Offline mode can sometimes leave stale cache files that cause resource merging issues:

  1. Go to File > Invalidate Caches / Restart
  2. Select Invalidate and Restart to clear all cached data and restart Android Studio
  3. 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

火山引擎 最新活动