android studio(gradle)报错ERROR: Unable to open PNG file原因

在将项目移动到新的SVN目录后,遇到编译错误,Gradle任务':AplikaceBeta1.0.1:mergeDebugResources'失败,原因是无法打开PNG文件。错误代码42,提示PNG文件无法打开。解决方案是检查Windows路径长度是否超过260字符限制,缩短项目路径或文件名,从而避免Windows的最大路径长度限制问题。通过调整文件路径,成功解决了编译问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在编译项目的时候碰到一个问题,代码完全相同的情况下,只是把项目移到SVN的另一个目录,编译无法通过

Gradle提示如下错误(不方便截自己的图片,网上转一个):


Gradle: Execution failed for task ':AplikaceBeta1.0.1:mergeDebugResources'. Failed to run command: C:\Users\David\AppData\Local\Android\android-studio\sdk\build-tools\android-4.2.2\aapt.exe s -i C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\exploded-bundles\AplikaceBeta101ProjectLibrariesFacebookUnspecified.aar\res\drawable\com_facebook_profile_picture_blank_square.png -o C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\res\all\debug\drawable\com_facebook_profile_picture_blank_square.png Error Code: 42 Output: C:\Users\David\Desktop\facebook-android-sdk-3.5\facebook-android-sdk-3.5\samples\AplikaceBeta1.0.1Project\AplikaceBeta1.0.1\build\exploded-bundles\AplikaceBeta101ProjectLibrariesFacebookUnspecified.aar\res\drawable\com_facebook_profile_picture_blank_square.png ERROR: Unable to open PNG file


老外的答案还是很给力的:

Are you using Windows? This error could happen if the generated build file path exceeds the Windows (not NTFS) max path length of 260 characters. Make sure your project path is not too long, use short names as well.

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

总结原因,就是项目文件路径太长,超过了长度限制,256个字符

通过修改文件名以及简化路径,减少相应文件的深度,成功解决了这个问题。

希望小伙伴们能快速解决掉这个问题。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值