Android 开发 PNG 图片问题:AAPT: error: file failed to compile.

  • 在 Android 开发中,构建 APK 时,出现如下错误信息

    Task :app:mergeReleaseResources FAILED
    Execution failed for task ':app:mergeReleaseResources'.
    Multiple task action failures occurred:
    A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
    Android resource compilation failed
    ERROR:D:\AndroidCode\DeviceController\app\src\main\res\mipmap-xhdpi\btn_exit.png: AAPT: error: file failed to compile.

    解读

    D:\AndroidCode\DeviceController\app\src\main\res\mipmap-xhdpi\btn_exit.png,AAPT 错误:文件编译失败

问题原因
  1. 这个错误表示 AAPT 在编译资源 btn_tk.png 时出了问题

  2. 检查发现 btn_tk.png 大小只有 0KB,且图片文件无法打开,图片文件已损坏

处理策略
  • 替换图片文件,确保图片文件未损坏