错误记录Android Studio 编译报错 ( AAPT: error: failed to read PNG signature: file does not start with PN )
Posted 韩曙亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误记录Android Studio 编译报错 ( AAPT: error: failed to read PNG signature: file does not start with PN )相关的知识,希望对你有一定的参考价值。
文章目录
一、报错信息
编译 android Studio 项目时 , 报错
AGPBI: "kind":"error","text":"Android resource compilation failed","sources":["file":"D:\\\\002_Project\\\\002_Android_Learn\\\\ClassLoader_Demo\\\\app\\\\src\\\\main\\\\res\\\\drawable\\\\abc.png"],"original":"ERROR:D:\\\\002_Project\\\\002_Android_Learn\\\\ClassLoader_Demo\\\\app\\\\src\\\\main\\\\res\\\\drawable\\\\abc.png: AAPT: error: failed to read PNG signature: file does not start with PNG signature.\\n ","tool":"AAPT"
AGPBI: "kind":"error","text":"Android resource compilation failed","sources":["file":"D:\\\\002_Project\\\\002_Android_Learn\\\\ClassLoader_Demo\\\\app\\\\src\\\\main\\\\res\\\\drawable\\\\abc.png"],"original":"ERROR:D:\\\\002_Project\\\\002_Android_Learn\\\\ClassLoader_Demo\\\\app\\\\src\\\\main\\\\res\\\\drawable\\\\abc.png: AAPT: error: file failed to compile.\\n ","tool":"AAPT"
> Task :app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> Android resource compilation failed
ERROR:D:\\002_Project\\002_Android_Learn\\ClassLoader_Demo\\app\\src\\main\\res\\drawable\\abc.png: AAPT: error: failed to read PNG signature: file does not start with PNG signature.
ERROR:D:\\002_Project\\002_Android_Learn\\ClassLoader_Demo\\app\\src\\main\\res\\drawable\\abc.png: AAPT: error: file failed to compile.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
57 actionable tasks: 3 executed, 54 up-to-date
二、解决方案
报错的原因是 Android 项目中使用的 png 格式的图片格式错误 ,
在 build.gradle 中的 android 层级配置了
aaptOptions
// aapt 附加参数
additionalParameters '--rename-manifest-package', 'com.example.classloader_demo2'
// 是否开启 png 图片优化检查
cruncherEnabled true
配置 , cruncherEnabled 配置的作用是开启 png 图片优化检查 ,
如果 png 图片格式错误 , 就会报上述错误 ;
解决方案 :
① 删除上述报错的 abc.png 图片即可 ;
② 如果想要保留上述图片 , 则将 " android # aaptOptions # cruncherEnabled " 设置为 false 即可 , 程序可编译完成 ;
aaptOptions
// aapt 附加参数
additionalParameters '--rename-manifest-package', 'com.example.classloader_demo2'
// 是否开启 png 图片优化检查
cruncherEnabled true
以上是关于错误记录Android Studio 编译报错 ( AAPT: error: failed to read PNG signature: file does not start with PN )的主要内容,如果未能解决你的问题,请参考以下文章
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段
错误记录Android Studio 编译时 Kotlin 代码编译报错 ( 升级支持库时处理 @NonNull 参数 )
错误记录Android Studio 编译报错 ( Invalid main APK outputs : EarlySyncBuildOutput )
错误记录Android Studio 编译报错 ( Invalid Gradle JDK configuration found )
错误记录Android Studio 编译报错 ( VirtualApp 编译 NDK 报错 | Error:A problem occurred configuring project ‘: )(代