You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

生成签名APK时mergeReleaseResources任务执行失败求助(非重复问题)

Fixes for :app:mergeReleaseResources & AAPT2 Error When Building Signed APK

Hey there, I know you’ve already checked all similar questions and they didn’t work because your logs are different—let’s dive into targeted fixes for this specific error you’re facing when generating a signed APK. This error typically stems from issues with your project’s resource files that AAPT2 (Android Asset Packaging Tool 2) can’t process correctly during the release build step.

Here are actionable steps to try:

  • Clean & Rebuild Your Project (Start Here)
    Cached build artifacts often cause odd resource conflicts. Run these commands in your terminal (or use Android Studio’s Build > Clean Project then Build > Rebuild Project):

    ./gradlew clean
    ./gradlew assembleRelease
    

    This wipes old build files and forces a fresh compilation of your release resources.

  • Audit Resource File Names for Invalid Characters
    AAPT2 is strict about naming rules. Double-check all your drawables, layouts, and string files to make sure they don’t have:

    • Spaces or special characters (only letters, numbers, underscores, and hyphens are allowed)
    • Capital letters (Android resource conventions prefer all lowercase)
      For example, rename Banner Image.png to banner_image.png if you have it.
  • Scan XML Files for Syntax Mistakes
    A tiny typo or missing tag in an XML file can break the resource merge. Go through any recently modified XML files (layouts, values, manifests) and look for:

    • Unclosed tags (like a missing </LinearLayout>)
    • Misspelled attributes (e.g., android:layout_hieght instead of android:layout_height)
      Use Android Studio’s built-in lint tool to automate this: right-click your app module > Analyze > Inspect Code and check for XML-related errors.
  • Update Android Gradle Plugin & Build Tools
    Outdated plugin versions can have bugs that trigger AAPT2 failures. Open your project-level build.gradle and update the plugin to the latest stable version:

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2' // Use the latest stable version available
    }
    

    Then sync your project, and make sure your app-level build.gradle has a matching build tools version:

    android {
        buildToolsVersion "33.0.2" // Match this to your plugin's compatible version
    }
    
  • Try Disabling AAPT2 (Temporary Workaround)
    If nothing else works, you can disable AAPT2 to test if the build succeeds (note: this isn’t ideal long-term, as AAPT2 offers better performance and error checking). Add this line to your app-level build.gradle:

    android {
        android.enableAapt2=false
    }
    

    Sync the project and attempt to generate the signed APK again.

  • Verify Corrupted Resource Files
    Sometimes drawable files (PNGs, vectors) get corrupted during import. Try re-adding any recently added images, or open them in an image editor to confirm they’re not damaged.


内容的提问来源于stack exchange,提问作者Muhammad Faizan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:49:57